springboot打成war包和jar包有点区别,在此记录一下,方便以后使用。
1.启动类Application需要修改,具体代码如下:
springboot每个版本的配置方法可能不太一样,我本地用的是1.5.10
package com.geneator.test.demo;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
@MapperScan(
basePackages = {"com.geneator.test.demo"},
annotationClass = Mapper.class)
public class DemoApplication extends SpringBootServletInitializer {
public DemoApplication() {
}
public static void main(String[] args) {
(new SpringApplicationBuilder(new Object[]{DemoApplication.class})).web(true).run(args);
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
SpringApplicationBuilder rest = builder.sources(new Class[]{DemoApplication.class});
return rest;
}
}
2.pom.xml中的配置如下:
<groupId>com.geneator.test</groupId>
<!--打成包的名字-->
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.js</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<!--mybatis 自动生成dao,model,mapper,generaotr插件-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webResources>
<resource>
<directory>src/main/resources</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
3.点击maven管理界面,先点击clean,而后点击package打包,最后在target目录下会生成相应的war包
mavenimage.png
网友评论