Maven打包,无法将application.properties配置打包

本文详细阐述了在Maven项目打包过程中遇到的application.properties配置文件丢失问题,通过调整pom.xml配置实现资源文件包含,并提供了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Maven打包,无法将application.properties配置打包

异常提示:
2022-02-12 04:55:04.912  WARN 6796 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productCategoryController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productCategoryServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productCategoryMapper' defined in file [D:\user\key\diancan\target\classes\com\wangheng\diancan\mapper\ProductCategoryMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2022-02-12 04:55:04.914  INFO 6796 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-02-12 04:55:04.926  INFO 6796 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-12 04:55:04.930 ERROR 6796 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).


Process finished with exit code 0

出现以上问题就是,maven打包过程中,没有将application.propreties打包,必须再,pom.xml中配置,打包时将配置文件打包的代码,即可

配置之前:运行Maven—》clean—》-----》pakage 之后再target目录下却没有,application.properties文件

在这里插入图片描述
需要在,maven的pom.xml文件中添加以下代码即可

    <build>
        <resources>
            <!--  配置将properties文件打印进去          -->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                //配置maven打包时,扫描以什么结尾的文件,加载到打包过程中
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>

**配置之后:**运行Maven—》clean—》-----》pakage,发现配置文件就存在了。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值