一. 需要将springboot打成一个war包,默认打成jar包。
二. 做如下修改
1.将pom.xml文件首部的jar改成war
<groupId>com.ysl</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<!--<packaging>jar</packaging> -->
<packaging>war</packaging>
2.pom.xml中设置war包名称
<build>
<finalName>boot</finalName>
</build>
3.pom.xml中spring-boot-starter-web依赖中移除tomcat模块
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
4.pom.xml中添加如下依赖。否则打包时会报javax.servlet.ServletException
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
spring-boot-starter-tomcat 是原来被传递过来的依赖,默认会打到包里,所以我们再次引入此依赖,并指定依赖范围为provided,这样tomcat 相关的jar就不会打包到war 里了。
5.修改启动类如下
@SpringBootApplication
public class SpringbootApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringbootApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
三. glassfish中启动
四. 访问服务,正常启动
但是这里的context-path和port都不是springboot中指定的,这里的路径端口都是glassfish配置的。即application.properties中如下配置是没有生效的。
porperty server.port=7989 server.servlet.context-path=/me
如果需要使用springboot 中的context-path和port,可将springboot做成wrapper 服务,参考教程:
SpringBoot-jar-作为Wrapper服务启动-Windows
SpringBoot-jar包作为Wrapper服务启动-Linux
五. 查看当前domain下的日志,发现日志中报错:
说不能找到这个类,在pom.xml中添加如下依赖即可。前面服务已经正常启动,说明该类不影响程序启动。
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>