用eclipse写的spring boot的后台程序,在eclipse下正常,打包成jar就不能运行,折腾了好多天,看完了整个互联网上的文章(^-^),也没解决,有一次想改一下Tomcat端口,无意间发现,发现运行jar包时,端号还是默认的8080,才意识到问题的根源时没有加载到application.properties,才导致的“Failed to configure a DataSource: 'url' attribute is not specified and....”,错误,
代码:
<resources>
<!--解决mybatis-generator-maven-plugin运行时没有将jdbc.properites文件放入target文件夹的问题 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.properties</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
注意红色部分,我的.properties文件是放在src/main/resources目录下的:
之后就正常了。上传服务器,ok!
错误提示如下:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'analystsServiceImpl': Unsatisfied dependency expressed through field 'analystsMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'analystsMapper' defined in URL [jar:file:/D:/myprogram/eclipse-jee-2020-12-R-win32-x86_64/liu/Java/SpringBoot_Back/target/analysts.jar!/BOOT-INF/classes!/com/analysts/mapper/AnalystsMapper.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 [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.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
2021-06-25 17:00:16.788 INFO 15776 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-06-25 17:00:16.818 INFO 15776 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-25 17:00:16.849 ERROR 15776 --- [ main] 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).