• required a bean of type 'javax.sql.DataSource' that could not be found.


    Description:
    
    Field dataSource in com.rjj.screw.ScrewApplication required a bean of type 'javax.sql.DataSource' that could not be found.
    
    The injection point has the following annotations:
        - @org.springframework.beans.factory.annotation.Autowired(required=true)
    
    The following candidates were found but could not be injected:
        - Bean method 'dataSource' in 'JndiDataSourceAutoConfiguration' not loaded because @ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
        - Bean method 'dataSource' in 'XADataSourceAutoConfiguration' not loaded because @ConditionalOnClass did not find required class 'javax.transaction.TransactionManager'
    
    
    Action:
    
    Consider revisiting the entries above or defining a bean of type 'javax.sql.DataSource' in your configuration.
    
    2020-08-30 16:49:01.968 ERROR 13937 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@7a1a3478] to prepare test instance [com.rjj.screw.ScrewApplicationTests@113e13f9]
    
    java.lang.IllegalStateException: Failed to load ApplicationContext

    出现了这个问题,找了好多,

    下边这个是我的pom

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.3.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.rjj</groupId>
        <artifactId>screw</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>screw</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
            <dependency>
                <groupId>org.freemarker</groupId>
                <artifactId>freemarker</artifactId>
                <version>2.3.30</version>
            </dependency>
    
            <!-- screw核心 -->
            <dependency>
                <groupId>cn.smallbun.screw</groupId>
                <artifactId>screw-core</artifactId>
                <version>1.0.3</version>
            </dependency>

        //之前没有加这个,换了mybatis-spring-boot-start也不行。这个是最原始的jdbc配置 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!--mysql driver--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.20</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

     我这里的问题:

     mysql-driver这个包只是驱动包,不是mysql的加载我们的配置的包,以前我们都是自己写连接,这里jdbc这个包就是springboot中加载我们配置的包。所以,不加就报错了,我这里使用的就是最初始的

    mysql的连接加载方式,所以添加其他的方式。比如mybatis就还是有问题。

    这个问题看每个人的情况来解决

  • 相关阅读:
    优雅地处理重复请求(并发请求)
    TSCTF2022(先挖个坑,太忙了呜呜呜)
    dotnet core 热重载调试Web Api
    Amazon Max deviation among all substrings
    javascript挑战编程技能第九题:数据结构
    javascript挑战编程技能第八题:99乘法表
    git获取代码和推送代码实例
    vue 项目打包和 安装项目依赖命令
    vscode 如何新建分支
    码云创建公钥 使其可以本地输入命令访问
  • 原文地址:https://www.cnblogs.com/renjianjun/p/13585727.html
Copyright © 2020-2023  润新知