1

My project use springBoot2,And it does not need to connect database,But springboot auto configurate datasource and throw an exception when starting project. I have add execute,but it does not work

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) @ImportResource("classpath:spring-config-platform.xml") public class JunoIotPlatformBoot1Application { public static void main(String[] args) { SpringApplication app = new SpringApplication(JunoIotPlatformBoot1Application.class); Map<String,Object> map = new HashMap<>(); map.put("server.port",8091); app.setDefaultProperties(map); app.run(args); } 

Because I megerate old spring project(xml) to springboot project,so ImportResource is necessary. log is:

 2018-04-16 16:19:01,141][restartedMain][WARN][org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:557)] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class ..... [2018-04-16 16:19:01,221][restartedMain][INFO][org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180)] Stopping service [Tomcat] [2018-04-16 16:19:01,259][restartedMain][ERROR][org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report(LoggingFailureAnalysisReporter.java:42)] *************************** APPLICATION FAILED TO START *************************** Description: Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). 
1
  • 2
    And 'spring.datasource.url' is in your application.properties? Commented Apr 16, 2018 at 11:27

2 Answers 2

1

You should check your build script, looks like you have some not needed starter there (something that is starts with spring-boot-starter-data-...)

Sign up to request clarification or add additional context in comments.

1 Comment

I was missing ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jdbc</artifactId> </dependency> ``` Thanks!
0

It can also happen when JPA dependency is set in the pom.xml with no database dependency.

To me, initializing the project with JPA was no enough - I needed to add the relevant database, e.g. H2.

To fix that, add your database dependency to the pom, e.g. for H2:

<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.