一. 需要将springboot打成一个war包,默认打成jar包。
二. 做如下修改
1.将pom.xml文件首部的jar改成war
1 2 3 4 5 6
|
<groupId>com.ysl</groupId> <artifactId>springboot</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot</name>
<packaging>war</packaging>
|
2.pom.xml中设置war包名称
1 2 3
|
<build> <finalName>boot</finalName> </build>
|
3.pom.xml中spring-boot-starter-web依赖中移除tomcat模块
1 2 3 4 5 6 7 8 9 10
|
<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
1 2 3 4 5
|
<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.修改启动类如下
1 2 3 4 5 6 7 8 9 10
|
public class 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中如下配置是没有生效的。
1 2
|
server.port=7989 server.servlet.context-path=/me
|
如果需要使用springboot 中的context-path和port,可将springboot做成wrapper 服务,参考教程:
SpringBoot-jar-作为Wrapper服务启动-Windows
SpringBoot-jar包作为Wrapper服务启动-Linux
五. 查看当前domain下的日志,发现日志中报错:
1 2 3 4 5
|
<dependency> <groupId>org.springframework.batch</groupId> <artifactId>spring-batch-core</artifactId> <version>4.1.1.RELEASE</version> </dependency>
|
近期评论