手记

spring boot 打包成war(亲测有效)

1,收下是修改pop.xml文件

   <groupId>com.imooc</groupId>
    <artifactId>demo</artifactId>
    <packaging>war</packaging>

修改

       <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>

增加

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
        <finalName>demo</finalName>
    </build>

2 下一步修改

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DemoApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

3 执行

4 把生成的war包放到tomcat的目录下,在浏览器上访问
http://192.168.9.101:8080/demo/hello
就可

1人推荐
随时随地看视频
慕课网APP