没有定义[javax.sql.DataSource]类型的限定bean

这是我的pom

    spring-boot-starter-parentspring-boot-starterspring-boot-starter-testcope>testcope>
        spring-boot-starter-webjackson-databindMysqLmysql-connector-javaspring-boot-starter-data-jpaspring-boot-starter-securitybedbed-jaspercope>providedcope>
    

这是我的主要课程

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletinitializer {

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

}

这是我的application.properties

#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

这是我的UserServiceImpl

@Service
public class UserServiceImpl  implements UserService{

     @Autowired
    private UserRepository userRepo;


    @Override
    @Transactional
    public void saveUser(MyUserEntity user) {
        userRepo.save(user);
        //testTransaction();
    }
}

**这是我的UserRepository **

@Repository
public interface UserRepository extends CrudRepository

我在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)
最佳答案
升级到了

 spring-boot-starter-parent

它工作正常.但它真的很奇怪,因为它与版本1.0.1一起使用.直到一小时前

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...