springboot war包 tomcat部署

springboot war包 tomcat 部署

JDK 1.8
springboot 2.2.0.RELEASE
tomcat-8

修改pom文件打包方式为war包

<packaging>war</packaging>

tomcat 依赖

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

修改build 里面的插件,尽量加上finalName这是打包之后的名字。

<build>
        <finalName>solrapp</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
</build>

生成war包
clean下,然后 package即可
在这里插入图片描述
也可以用命令的方式
输入:mvn clean package -Dmaven.test.skip=true 一般跳过测试
在这里插入图片描述
然后将target下的war包,部署在tomcat下即可。

注:如果用@PropertySource()这样的方式引用配置文件的话。

在idea中@PropertySource(“solr.properties”)这样配置可以找到classpath下的solr.properties配置文件;

如果打成war后,部署到tomcat下启动会报错,找不到solr.properties配置文件;需要修改成@PropertySource(“classpath:solr.properties”)才可以。

猜你喜欢

转载自blog.csdn.net/lchlaughing/article/details/102913770