1,jsp 无法解析问题
在正常的目录结构下(单个工程)加入tomcat支持
pom配置文件需要配置如下:
<packaging>war</packaging>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!--<scope>provided</scope>--> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency>
启动类型需要继承:
SpringBootServletInitializer
及覆盖方法:
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(BootJspServer.class); }
这样配置可以正常运行并正常解析jsp
但如你的项目为Maven工程及结构如下:
parent
children-A
children-B
children-web
其中childre-web 为你的web项目则解析会出现无法解析问题如果解析?这时需要你指定webapp的路径
配置如下:
@Component
public class TomcatConfig {
@Value("${south.config.tomcat.webapp}")
private String webappRoot;
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
ConfigurableEmbeddedServletContainer factory = new TomcatEmbeddedServletContainerFactory();
factory.setDocumentRoot(new File(webappRoot));
return (EmbeddedServletContainerFactory) factory;
}
}
其中@Value中的值为:你所在工程的webapp文件夹路径
2,同一个tomcat无法同时运行一个服务问题
我将开发好的项目部署到服务器上时,在同一个tomcat 下部署两个web 服务则现在了第二个服务无法正常启动问题。解决方法如下:
endpoints:
jmx:
domain: xx
spring:
jmx:
default-domain: xx
其中xx为你的服务名称