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,发现配置文件就存在了。