我的项目结构,因此根目录在pom.xml中声明了2个模块
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>svpm-service</module>
<module>svpm-web</module>
</modules>
<groupId>md.svpm</groupId>
<artifactId>svpm</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>svpm</name>
Thymeleaf如何无法将路径和配置获取到我的模板文件夹?我有一个多模块项目,其中前端是一个单独的模块,试图至少从放置在根目录中的WebConfig.java使其正常运行,但即使这样也无法获得路径。
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(this.applicationContext);
templateResolver.setPrefix("classpath:/templates/"); // < - here the code
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(true);
return templateResolver;
}
Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
第一种情况:即使我将WebConfig.java中的路径更改为另一个路径-它仍然显示
找不到模板位置:classpath:/ templates /(请添加一些模板或检查您的Thymeleaf配置)
Second case: if I add the lines below to all of the application.properties it considers only the one from svpm-service and still nothing
spring.thymeleaf.check-template=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
Please point me in the right direction.
The problem was in specifying the modules and the way Spring Boot reads configurations for specific module, it is easy to understand that:
In root pom.xml I have the followinf declaration of 3 modules:
<modules>
<module>application</module>
<module>frontend</module>
<module>service</module>
</modules>
In application's pom.xml I have only the dependency for service module
<dependency>
<groupId>md.svpm</groupId>
<artifactId>service</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
Next, in service I have the frontend dependency
<dependency>
<groupId>md.svpm</groupId>
<artifactId>frontend</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
因此,以这种方式,服务了解前端,而应用程序了解服务,这是一个设计良好的模块应用程序链。它不会以其他方式工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句