1. 程式人生 > >spring boot 匯出jar執行出錯的小記

spring boot 匯出jar執行出錯的小記

1、內嵌web容器預設scope是provided,需要刪掉scope,不使用外部容器。

2、若專案中有多個main方法,需指定spring boot啟動的入口,如下:

    <properties>
        <!-- The main class to start by executing java -jar -->
        <start-class>com.amazing.ApplicationMain</start-class>
    </properties>

3、最好不用eclipse自帶的maven打包吧,用 maven clean package

      並且必須加入maven的依賴:

                <dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-maven-plugin</artifactId>
		    <version>1.3.0.M2</version>
		    <type>maven-plugin</type>
		</dependency>

4、pom中使用了spring-boot-starter-parent的話,一定要加上:
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

5、eclipse打包有時候不會報一些錯,但是用maven就會,所以官方也推薦maven打包


6、spring boot推薦用嵌入式容器來建立可執行jar,在構建和執行時用這個fat jar來獨立執行。