我已经将Spring MVC 5.2.5迁移到了Spring Boot 2.2.6。 该项目有许多JSP页面,并使用Apache磁贴来构建模板。
Spring应用程序类如下:
Pom.xml依赖项是:
<artifactId>test</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.35</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
</dependencies>
WebConfiguration类:
@Configuration
@EnableWebMvc
@EnableAspectJAutoProxy
@Slf4j
@EnableSwagger2
public class WebConfiguration implements WebMvcConfigurer
{
@Autowired
private CommonConstants commonConstants;
@Autowired
private RestInterceptor restInterceptor;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private ApplicationContext applicationContext;
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(120*1000L);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
ResourceHandlerRegistration handler = registry.addResourceHandler("/resources/**");
try {
if (StringUtils.hasText(commonConstants.getBflowResourceDir())) {
for (String location
Arrays.asList(StringUtils.split(commonConstants.getBflowResourceDir(), ","))) {
log.info("Using custom directory for resources: " + location);
handler.addResourceLocations("file:" + location + "/");
}
}
handler.addResourceLocations("/dist/");
}
catch (Exception e) {
log.error("error", e);
}
handler.addResourceLocations("/WEB-INF/dist/");
}
@Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
String[] definitions = new String[] {"WEB-INF/tiles.xml"};
tilesConfigurer.setDefinitions(definitions);
tilesConfigurer.setCheckRefresh(true);
return tilesConfigurer;
}
@Bean
public TilesViewResolver tilesViewResolver() {
TilesViewResolver tilesViewResolver = new TilesViewResolver();
tilesViewResolver.setOrder(-1);
return tilesViewResolver;
}
}
磁贴配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="simple_template" template="/WEB-INF/templates/simple_template.jsp">
<put-attribute name="global" value="/WEB-INF/views/general/global.jsp" />
</definition>
<definition name="main_template" extends="simple_template">
<put-attribute name="body">
<definition template="/WEB-INF/templates/main_template.jsp">
<put-attribute name="header_include" value="/WEB-INF/views/general/header_include.jsp" />
<put-attribute name="header" value="/WEB-INF/views/modules/header.jsp" />
</definition>
</put-attribute>
</definition>
<definition name="content_template" extends="main_template">
<put-attribute name="main_body" cascade="true">
<definition template="/WEB-INF/templates/content_template.jsp" />
</put-attribute>
</definition>
<definition name="login" extends="content_template">
<put-attribute name="title" value="login.title" cascade="true" />
<put-attribute name="content" value="/WEB-INF/views/login/login.jsp" cascade="true" />
</definition>
<definition name="home" extends="main_template">
<put-attribute name="title" value="home.title" cascade="true" />
<put-attribute name="main_body" value="/WEB-INF/dist/ng2/index-ng2.jsp" cascade="true" />
</definition>
<definition name="single_page_message/*" extends="content_template">
<put-attribute name="title" value="{1}" cascade="true" />
<put-attribute name="content" value="/WEB-INF/views/general/single_page_message.jsp" cascade="true" />
</definition>
<definition name="access_error" extends="simple_template">
<put-attribute name="body" value="/WEB-INF/views/general/single_page_message.jsp" type="template" />
</definition>
<definition name="standalone/**" extends="simple_template">
<put-attribute name="inner" value="{1}" cascade="true" />
<put-attribute name="title" value="{1}" cascade="true" />
<put-attribute name="body">
<definition template="/WEB-INF/templates/standalone_template.jsp">
<put-attribute name="header_include" value="/WEB-INF/views/general/header_include.jsp" />
</definition>
</put-attribute>
</definition>
<definition name="**.jsp" template="{1}.jsp" />
<definition name="**" extends="simple_template">
<put-attribute name="body" value="/WEB-INF/views/{1}.jsp" type="template" />
</definition>
</tiles-definitions>
服务器成功启动,并且我正在从JSP页面获取视图。 但是,磁贴配置尚未加载的页面没有页眉和页脚。
我想念什么?
感谢所有帮助