1. 程式人生 > >SpringCloud-Maven打包--問題疑惑與解決

SpringCloud-Maven打包--問題疑惑與解決

1.專案在webapp下的web-inf下引入了依賴包,run as?maven install報錯:
找不到符號

右鍵專案->MAVEN->Update Project Configuration
然後clean相關專案
再打包

依賴包就在maven裡面了

2.spring-boot-maven-plugin 打包後class path resource [mybatis-config.xml ] cannot be opened because it do
本地啟動沒問題,打成jar包後找不到xml檔案:

<build>
        <plugins
>
<!-- 支援maven war/jar打包 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <source>1.8</source
>
<target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>

原因主要是mapping目錄裡面的檔案都是xml檔案並不是.java檔案,而maven打包預設的src/main/java的是Java檔案,它不會打包裡面的xml檔案,所以在打包之後裡面不會有mapping。

https://blog.csdn.net/jgj0129/article/details/53112738

<!-- maven預設不打*.xml的檔案,所以需要特殊標明出來 -->
<!-- maven預設不打*.xml的檔案,所以需要特殊標明出來 -->
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>**/*.*</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
</build>

3.If you want an embedded database please put a supported one on the classpath.
說是資料庫連不上,可是我改了好多次jdbc和驅動,都不可以!!!!!原來是mybatis問題,錯誤提示過於坑。

因為是properties不支援:雖然本地沒問題可是打包後jar命令執行就是報錯:

mybatis.mapperLocations:classpath:mappers/*.xml  
mybatis.configLocation:classpath:mybatis-config.xml

改成

mybatis.mapperLocations=classpath:mappers/*.xml  
mybatis.configLocation=classpath:mybatis-config.xml

這個配置錯了報的還挺多的,不過一改成這樣就全好了

4.spring-boot-maven-plugin打第三方jar包

網上有兩個方法:
第一個就是,全部把第三方jar包全部放在maven庫裡面加上依賴,和其他jar一樣從庫裡找
這個感覺太麻煩了沒有用

第二個是,在pom檔案中配置一個專案中依賴,

<dependency>
    <groupId>com.cc.cqp</groupId>
    <artifactId>cqp-riskpremium-commons-codec</artifactId>
    <version>1.1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/commons-codec-1.3.jar</systemPath>
</dependency>

主要是<scope>system</scope>,意思是這個jar包從專案路徑裡面找而不是從maven庫裡找,<systemPath>配置的專案查詢路徑
剩下的

<groupId>com.cc.cqp</groupId>
    <artifactId>cqp-riskpremium-commons-codec</artifactId>
    <version>1.1.0</version>

隨便編寫就好了,不和其他重合即可

然後在

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <includeSystemScope>true</includeSystemScope>
    </configuration> 
</plugin>

加上<includeSystemScope>true</includeSystemScope>,意思代表會把剛才的本專案中的本地jar打進最後的包裡面

5.打成jar後老是啟動不了服務
No active profile set, falling back to default profiles: default
Starting service [Tomcat]
Starting Servlet Engine: Apache Tomcat/8.5.16
Initializing Spring embedded WebApplicationContext

就停止了

配置檔案的問題

服務停止一般都是配置檔案惹的禍,發現

spring.datasource.tomcat.max-wait=1000
spring.datasource.tomcat.max-active=30
spring.datasource.tomcat.test-on-borrow=false

改為

spring.datasource.max-wait=1000
spring.datasource.max-active=30
spring.datasource.test-on-borrow=false

即可