我有一个Spring Boot应用程序,它可以创建胖子罐和胖子的分解版本,如下所示,
/META-INF/resources/index.jsp,如下所示:
Spring Boot Executable jar structure
我尝试访问application.properties中的前缀,
spring.mvc.view.prefix = /WEB-INF/resources/ - No luck
spring.mvc.view.prefix = /META-INF/resources/ - No luck
spring.mvc.view.prefix = /resources/ - No luck
那么这个正确的前缀是什么?预先感谢!
答案 0 :(得分:0)
您可以执行以下操作:
@Configuration
@EnableWebMvc
public class ApplicationConfigurerAdapter extends WebMvcConfigurerAdapter{
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/web-resources/**").addResourceLocations("/resources/").setCachePeriod(300);
}
}
答案 1 :(得分:0)
确保已将Maven插件配置为可执行文件。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
要在docker容器中运行此war文件,只需像运行jar文件一样运行它即可。在您的Dockerfile中,使用您的战争名称:
ENTRYPOINT exec java -jar /my_project.war