SpringCloud-Maven打包--问题疑惑与解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cc907566076/article/details/80438334

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

即可

猜你喜欢

转载自blog.csdn.net/cc907566076/article/details/80438334