Spring 带弹簧靴的Maven模块
我试图将Maven配置为使用多模块的Spring Boot,这是我的结构:Spring 带弹簧靴的Maven模块,spring,maven,spring-mvc,spring-boot,Spring,Maven,Spring Mvc,Spring Boot,我试图将Maven配置为使用多模块的Spring Boot,这是我的结构: - Parent ------ WebClient ------------ scr/main/java/config ---> Config Files ------------ scr/main/java/resources/WEB-INF ---> Template Files ------ Core ------ Services ------ Server 我有一个配置文件,其中放置了我的View
- Parent
------ WebClient
------------ scr/main/java/config ---> Config Files
------------ scr/main/java/resources/WEB-INF ---> Template Files
------ Core
------ Services
------ Server
我有一个配置文件,其中放置了我的ViewResolver:
@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver setupViewResolver() {
// View Resolver
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
viewResolver.setPrefix("/WEB-INF/");
viewResolver.setSuffix(".jsp");
viewResolver.setViewClass(JstlView.class);
return viewResolver;
}
以下是我的父pom.xml模块和依赖项:
<modules>
<module>core</module>
<module>services</module>
<module>server</module>
<module>webclient</module>
</modules>
<dependencyManagement>
<dependencies>
<!-- =========================== Spring ======================= -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<!-- Spring Security and MVC dependences -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.1.0.RC1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.1.0.RC1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>mygroup</groupId>
<artifactId>services</artifactId>
</dependency>
<dependency>
<groupId>mygroup</groupId>
<artifactId>webclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
当我启动我的应用程序时,我看到我的映射工作正常,似乎一切正常,但问题是Spring找不到我的模板:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/index.jsp
我的配置有什么问题?我应该将模板文件放在哪里?
谢谢你的帮助
编辑:
如果我把我的模板文件放在服务器项目(Server\src\main\webapp)上,它就可以工作了!所以如何使服务器读取webclient项目模板?我需要那个子模块中的模板
编辑2:
要避免使用“jsp”文件,请参阅答案和注释我认为这与-您不能仅从类路径中的任何位置读取jsp有关(而这适用于其他模板引擎)。您收到的消息是警告消息。它表示视图渲染器遇到错误并触发了到默认映射的重定向,该映射未实现。真正的错误是触发此重定向的错误。在此消息之前,请提供您的日志详细信息。我的服务器控制台没有任何错误:
2016-03-31 11:05:14.562 INFO 8824-[main]server.ServerRunner:在4.628秒内启动ServerRunner(JVM运行5.379)
我认为错误是在错误页面上打印的未找到
你对服务器的pom是什么意思?服务器的pom是否继承自父pom?建议在使用Boot时不要使用特定于Spring项目的版本。只需从Spring Boot的父pom继承,并将版本号保留为空,Spring就会处理它们。请注意您在webapps
文件中放置的内容<如果应用程序将打包为jar,则不要使用src/main/webapp目录。虽然这个目录是一个通用的标准,它只适用于war打包,如果您生成一个jar,大多数构建工具都会自动忽略它。您可以在以下位置找到更多信息:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-特色spring mvc静态内容
感谢您的回答!我不知道这个限制。但我想我还需要别的东西。。。如果我更改ViewResolver并尝试提供html模板文件,我会遇到相同的错误未找到:/WEB-INF/index.html
您是否可以尝试不使用自定义解析器,不使用自定义配置(只是一个thymeleaf初学者和src/main/resources/templates
中的一个模板?正如Drew1208所指出的,如果我将模板文件放在server/src/main/resources/templates
thymeleaf可以找到它,并且它可以工作……但是如果我将文件放在webclient/src/main/resources/templates
中,webapp的位置可能是一个问题仍然无法工作(模板可能不存在或任何已配置的模板解析程序都无法访问
)我需要“webclient”项目中的模板文件,是否有解决方案?确保客户端JAR将这些模板放在正确的位置(类/模板
?)您的web项目取决于客户端jar的正确版本(您可以jar-tvf
可执行jar/war中包含的客户端jar)
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/index.jsp