当前位置: 首页 > 知识库问答 >
问题:

未定义[javax.sql.datasource]类型的限定bean

宰父深
2023-03-14

这是我的pom

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.1.RELEASE</version>
    </parent>


    <dependencies>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
            <exclusion>
               <groupId>com.fasterxml.jackson.core</groupId>
               <artifactId>jackson-databind</artifactId>
        </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
     <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- Spring Boot Maven -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {

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

}
#server.contextPath=/SpringBootExamples
server.port=8888
logging.file=F:/new-spring-boot/Test-Spring-Boot.log

# spring security configuration
security.user.name=admin
security.user.password=admin1
management.security.role=SUPERUSER
spring.data.jpa.repositories.enabled=true

spring.datasource.url= jdbc:mysql://localhost:3306/springbootdb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop
@Service
public class UserServiceImpl  implements UserService{

     @Autowired
    private UserRepository userRepo;


    @Override
    @Transactional
    public void saveUser(MyUserEntity user) {
        userRepo.save(user);
        //testTransaction();
    }
}
@Repository
public interface UserRepository extends CrudRepository<MyUserEntity, Long>{


}

java-jar target/example-spring-boot-rest-1.0-snapshot.war时出现以下错误

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSecurityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService javabeat.net.springboot.config.WebSecurityConfig.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySpringUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private final javabeat.net.springboot.service.UserService javabeat.net.springboot.service.MySpringUserDetailsService.userService; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl' defined in URL [jar:file:F:\new-spring-boot\target\example-spring-boot-rest-1.0-SNAPSHOT.war!/WEB-INF/classes!/javabeat/net/springboot/service/UserServiceImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [javabeat.net.springboot.dao.UserRepository]: : Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#188ad80b' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#188ad80b': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.orm.jpa.JpaVendorAdapter)] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#188ad80b' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#188ad80b': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.orm.jpa.JpaVendorAdapter)] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)

共有1个答案

汪安然
2023-03-14

我升级到

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
    </parent>

效果很好。但这真的很奇怪,因为它在1.0.1.版本上也一直工作到一个小时之前。

 类似资料:
  • 你知道为什么我会犯这个错误吗?我是Spring的新手,冬眠的,junit的。总之,我认为我应该这样做。或者我该怎么做这个测试类? 我在某处读到导致问题的原因是extends AbstractTransactionalJUnit4SpringContextTest,如果没有它,我就不会再出现这个错误了。

  • 我按照教程创建批处理作业https://spring.io/guides/gs/batch-processing/,如果我从MainClass运行应用程序,则程序正在运行。 但是,当我使用运行相同的代码时,我会得到关于未找到DataSource的错误。我的pom文件是 https://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0 org.springfra

  • 问题内容: 我已将Java动态Web项目导入Eclipse IDE(已在Eclipse IDE中实现并正常工作)。 运行项目时,我收到“ 类型未定义”错误。 我已经按照结构将每个文件复制到IDE中,并且工作已完成。 现在我只想知道为什么在导入项目时出现此错误。有人遇到过同样的问题吗?请让我知道我可能犯了什么错误。 问题答案: 当我在IntelliJ中使用的servlet-api版本与Tomcat8

  • 问题内容: 我遇到了这个JSON代码。我注意到它利用了价值。在哪里可以找到有关此值类型的更多信息? 问题答案: *即使在javascript中有效, *undefined 也不是有效的json值。根据官方json标准 (ECMA-404,第5节): JSON值可以是对象,数组,数字,字符串,true,false或null。 对于json,请使用 null 而不是 undefined :

  • 我是一个新的编码和上课目前,我不知道什么似乎是这里的问题,但我试图阅读和挑选特定的信息,从一个单独的文本文件。非常感谢任何帮助!

  • 试图向OpenLDAP添加一个新属性,但总是碰壁。我正在尝试向架构添加ipPhone属性,因为我不能在默认的telephoneNumber属性中包含*数字。 下面是我的LDIF文件,用于创建新属性并将其与objectClass类似。 我已经测试和谷歌了几个小时,但一直无法解决这个问题或找出我错过了什么!