Spring Boot 显示对索引路径的 HTTP 请求,但不显示任何其他映射。
我创建了一个在 localhost:8060 上运行的 Spring Boot 应用程序。问题是,当我在浏览器上运行 localhost:8060 时,它可以工作,但是当我运行任何其他请求时,它会显示“出现意外错误(type=Forbidden,status=403)。拒绝访问'。在日志中它说它找到了正确的方法,即它正确映射但仍然抛出这个错误。
问候.java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Main application to launch spring boot.
*/
@RestController
public class Greetings {
/**
* Main application to launch spring boot.
*/
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
@RequestMapping("/testing123")
public String indextest() {
return "Testing";
}
}
服务器应用程序
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
/**
* Main application to launch spring boot.
*/
@SpringBootApplication
@EnableAutoConfiguration
@EnableAsync
public class ServerApplication {
private static Logger logger = LoggerFactory.getLogger(ServerApplication.class);
/**
* Start the Spring Boot application.
*
* @param args command line arguments
*/
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(ServerApplication.class, args);
logger.info("Sample Application started with context {}", context.getDisplayName());
}
}
所以它确实显示“来自 Spring Boot 的问候!” 当我去 localhost:8060 但在 localhost:8060/testing123 上抛出错误
摇曳的蔷薇
相关分类