[英]the first application with spring boot is not working
我想尝试春季安全。 我从官方网站( https://spring.io/guides/gs/securing-web/ )打开了说明。 我已经按部就班地做了第一部分(准备春季安全性应用程序)。 根据说明,此应用程序必须有效:
1)我做了Maven的依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
2)创建第一页:src \\ main \\ resources \\ templates \\ home.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Spring Security Example</title>
</head>
<body>
<h1>Welcome!</h1>
<p>Click <a th:href="@{/hello}">here</a> to see a greeting.</p>
</body>
</html>
3)创建第二页:src \\ main \\ resources \\ templates \\ hello.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
4)创建配置:
package hello;
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/").setViewName("home");
registry.addViewController("/hello").setViewName("hello");
registry.addViewController("/login").setViewName("login");
}
}
就这样 我尝试运行此应用程序,但所有路径(/,/ home,/ hello)都显示错误404
您能解释一下我想念的内容以及为什么我的应用程序无法正常工作吗?
检查pom.xml
依赖项,尝试添加spring-context,spring-core,spring-mvc。 另外,您可以尝试在不添加maven的情况下重新创建您的项目,而只是在项目中添加了spring和其他文件(有时对我有用)。
我现在确定,但是尝试在application.properties中添加此配置
spring.mvc.view.prefix=templates/
spring.mvc.view.suffix=.html
我的带有main
方法的类Application
(执行应用程序)位于另一个包中,然后位于我的MvcConfig
类中,这就是Spring Boot无法找到配置的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.