Error creating bean with name ‘XXXX‘: Unsatisfied dependency expressed through field

用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).

引用中提到了一个错误信息"Error creating bean with name 'chartServiceImpl': Unsatisfied dependency expressed through field"。这个错误表示在创建名为'chartServiceImpl'的bean时,它的依赖没有得到满足。具体原因在于该bean的某个字段的依赖无法找到。然而,根据提供的引用内容,我没有找到与该错误具体相关的信息。为了解决这个问题,你可以尝试以下方法: 1. 检查'chartServiceImpl'的代码,特别是它的字段注入是否正确。确保依赖的字段被正确声明并且有相应的注解,如@Autowired或@Resource。还要确保依赖的类型正确,并且存在于Spring容器中。 2. 检查依赖的字段所在的类是否已经添加了相应的注解,比如@Service或@Repository。这些注解告诉Spring容器将这个类作为bean进行管理。 3. 检查依赖的字段的类型是否正确。如果类型不匹配,可能会导致依赖无法注入成功。 4. 如果以上步骤都没有解决问题,可以考虑检查相关实体的字段类型是否正确。如果字段类型错误,也可能导致依赖无法注入成功。 总之,要解决"Error creating bean with name 'chartServiceImpl': Unsatisfied dependency expressed through field"错误,你需要仔细检查代码中的依赖注入和相关注解,确保依赖的类型和声明都正确无误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [解决异常Error creating bean with name ‘xxxxxController‘: Unsatisfied dependency expressed through ...](https://blog.csdn.net/weixin_46870864/article/details/128132222)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值