找不到dataSource

时间:2016-08-23 18:57:00

标签: java spring spring-mvc

我有以下代码。当我尝试执行它时,我得到了

  

org.springframework.beans.factory.UnsatisfiedDependencyException:   创建名为“x”的bean时出错:表示不满意的依赖项   通过字段'dataSource':没有类型的限定bean   找到依赖项[javax.sql.DataSource]的[javax.sql.DataSource]:   预计至少有1个豆有资格成为autowire候选人   这种依赖。依赖注释:   {@ org.springframework.beans.factory.annotation.Autowired(所需=真)};   嵌套异常是   org.springframework.beans.factory.NoSuchBeanDefinitionException:没有   为依赖项找到类型[javax.sql.DataSource]的限定bean   [javax.sql.DataSource]:预计至少有1个符合条件的bean   autowire候选人这种依赖。依赖注释:   {@ org.springframework.beans.factory.annotation.Autowired(所需=真)}

我的切入点:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

    }
}

我尝试在resources

中添加application.properties个文件夹中的这些行
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/y
jdbc.username=a
jdbc.password=b

spring.datasource.url=jdbc:mysql://localhost:3306/y    spring.datasource.username=a
spring.datasource.password=b
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.driverClassName=com.mysql.jdbc.Driver

或者我尝试添加此上下文配置:

<!-- Initialization for data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/cfa"/>
    <property name="username" value="cfa_user"/>
    <property name="password" value="cfa_pw"/>
</bean>

这些都没有奏效。还有其他想法吗?谢谢!

我必须提到我的DAO正在扩展

public abstract class BaseDAO extends NamedParameterJdbcDaoSupport {
    private @Autowired DataSource dataSource;

    @PostConstruct
    public void initDataSource(){
        setDataSource(dataSource);
    }
}

依赖

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mobile</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-social-facebook</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>19.0</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.restdocs</groupId>
        <artifactId>spring-restdocs-mockmvc</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

0 个答案:

没有答案