Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

前端 未结 28 2526
天命终不由人
天命终不由人 2020-11-30 19:57

I am working on a Spring Boot Batch example with MongoDB and I have already started the mongod server.

When I launch my application, I

相关标签:
28条回答
  • 2020-11-30 20:42

    If you're using Gradle, rebuild Gradle can solve this problem.

    0 讨论(0)
  • 2020-11-30 20:42

    It's happening because the @valerio-vaudi said.

    Your problem is the dependency of spring batch spring-boot-starter-batch that has a spring-boot-starter-jdbc transitive maven dependency.

    But you can resolve it set the primary datasource with your configuration

     @Primary
     @Bean(name = "dataSource")
     @ConfigurationProperties(prefix = "spring.datasource")
     public DataSource getDataSource() {
          return DataSourceBuilder.create().build();
     }
    
     @Bean
     public JdbcTemplate jdbcTemplate(DataSource dataSource) {
          return new JdbcTemplate(dataSource);
     }
    
    0 讨论(0)
  • 2020-11-30 20:42

    In my case

    spring.profiles = production // remove it to fix
    

    in application.properties was the reason

    0 讨论(0)
  • 2020-11-30 20:43

    I think when importing modules you have imported another package, Go to modules and remove al of them. After that import modules from the package of the project

    0 讨论(0)
  • 2020-11-30 20:45

    I removed an obsolete dependency on mybatis in the pom.xml to get mine running.

    0 讨论(0)
  • 2020-11-30 20:46

    Add this annotation in main java file

    @EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
    
    0 讨论(0)
提交回复
热议问题