spring boot 打包成jar和war

修改packageing 为war

添加tomcat

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>runtime</scope>

三 用maven 插件打包

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
</plugins>

四 打包

war包 在项目target目录中生成

启动war包 java -jar xxx.war

注: 用命令启动时 在Filtr 拦截器 找不到 依赖注入的service

我是用的监听器 在

doFilter方法中加入

workersessionsservice = (WorkersessionsManager) WebAppContextListener.getSpringContext().getBean("workersessionsservice");
如果其它方法请指出谢谢

打成jar

修改packageing 为jar

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

用于编译jsp
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <!--<scope>runtime</scope>-->
</dependency>

<resources>
            <resource>
                <!-- 指定resources插件处理哪个目录下的资源文件 -->
                <directory>src/main/webapp</directory>
                <!--注意此次必须要放在此目录下才能被访问到 -->
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
        </resources>
如果不添加会访问不到页面

 打包方式和上面一样

猜你喜欢

转载自blog.csdn.net/qq_31225707/article/details/79547236