在类路径资源中定义了一个名为“数据源”的bean。

时间:2023-01-26 09:40:03

I have Spring Boot web application. It's centered around RESTful approach. All configuration seems in place but for some reason MainController fails to handle request. It results in 404 error. How to fix it?

我有Spring引导web应用程序。它以RESTful方式为中心。所有配置似乎都已就绪,但由于某些原因,MainController无法处理请求。它会导致404错误。如何修复它吗?

@Controller
public class MainController {

    @Autowired
    ParserService parserService;

    @RequestMapping(value="/", method= RequestMethod.GET)
    public @ResponseBody String displayStartPage(){
        return "{hello}";
    }
}

Application

应用程序

@Configuration
@ComponentScan(basePackages = "")
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer{
        public static void main(final String[] args) {
            SpringApplication.run(Application.class, args);
        }

        @Override
        protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
}

ParserController

ParserController

@RestController
public class ParserController {

    @Autowired
    private ParserService parserService;

    @Autowired
    private RecordDao recordDao;

 private static final Logger LOG = Logger.getLogger(ParserController.class);

    @RequestMapping(value="/upload", method= RequestMethod.POST)
    public @ResponseBody String fileUploadPage(
   }
}

UPDATE

更新

Seems like MySQL cannot be initialized by Spring....

看起来MySQL无法在Spring中初始化

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; 

nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; 

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Instantiation of bean failed; 

nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()] threw exception; 

nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.

UPDATE2

更新2

application.properties

application.properties

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/logparser
spring.datasource.username=root
spring.datasource.password=root

spring.jpa.database = MYSQL
spring.jpa.show-sql = true

# Hibernate
hibernate.dialect: org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql: true
hibernate.hbm2ddl.auto: update
entitymanager.packagesToScan: /

UPDATE4

UPDATE4

Seems lite controllers not responding eventhough @RequestMapping are set. Why might it be?

看起来lite控制器没有响应,尽管@RequestMapping已经设置好了。为什么会这样呢?

PS. It occurs when I run Maven's lifecycle test. When running in degub mode in IntelliJ there is no error outputted.

它发生在我运行Maven的生命周期测试时。当在IntelliJ中运行degub模式时,没有输出错误。

UPDATE5

UPDATE5

Also I use this DAO as explained in tutorial....

我也用这刀作为解释教程....

public interface RecordDao extends CrudRepository<Record, Long> {
}

http://blog.netgloo.com/2014/10/27/using-mysql-in-spring-boot-via-spring-data-jpa-and-hibernate/

http://blog.netgloo.com/2014/10/27/using-mysql-in-spring-boot-via-spring-data-jpa-and-hibernate/

UPDATE6

UPDATE6

I did changed my application properties. And tried every single combination but it refuses to work. ;(

我确实改变了我的应用程序属性。尝试了每一个组合,但它拒绝工作。;(

Maven output:

Maven输出:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running IntegrationTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.365 sec <<< FAILURE! - in IntegrationTest
saveParsedRecordsToDatabase(IntegrationTest)  Time elapsed: 2.01 sec  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.

14 个解决方案

#1


61  

Looks like the initial problem is with the auto-config.

看起来最初的问题是自动配置。

If you don't need the datasource, simply remove it from the auto-config process:

如果您不需要数据源,只需从自动配置过程中删除它:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

#2


14  

From the looks of things you haven't passed enough data to Spring Boot to configure the datasource

从外观来看,您还没有传递足够的数据到Spring引导来配置数据源。

Create/In your existing application.properties add the following

创建/在你现有的应用程序。添加以下属性

spring.datasource.driverClassName=
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=

making sure you append a value for each of properties.

确保为每个属性追加一个值。

#3


8  

Maybe you forgot the MySQL JDBC driver.

可能忘记了MySQL JDBC驱动程序。

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.34</version>
</dependency>

#4


5  

I was getting the same error, found out it was due to some of the dependencies missing in my pom.xml like that of Spring JPA, Hibernate, Mysql or maybe jackson. So make sure that dependencies are not missing in your pom.xml and check their version compatibility.

我得到了同样的错误,发现这是由于我的pom中缺少了一些依赖项。像Spring JPA、Hibernate、Mysql或者jackson这样的xml。因此,请确保您的pom中不缺少依赖项。xml并检查它们的版本兼容性。

<!-- Jpa and hibernate -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.3.Final</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>

#5


4  

The hibernate.* properties are useless, they should be spring.jpa.* properties. Not to mention that you are trying to override those already set by using the spring.jpa.* properties. (For the explanation of each property I strongly suggest a read of the Spring Boot reference guide.

hibernate。属性是无用的,它们应该是spring.jpa.*属性。更不必说,您正在试图通过使用spring.jpa.*属性来覆盖已经设置的那些。(对于每个属性的解释,我强烈建议阅读Spring引导参考指南。

spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql = true

# Hibernate
spring.jpa.hibernate.ddl-auto=update

Also the packages to scan are automatically detected based on the base package of your Application class. If you want to specify something else use the @EntityScan annotation. Also specifying the most toplevel package isn't really wise as it will scan the whole class path which will severely impact performance.

还可以根据应用程序类的基本包自动检测包。如果您想指定其他东西,请使用@EntityScan注释。另外,指定最顶层的包并不明智,因为它会扫描整个类路径,这会严重影响性能。

#6


1  

In my case this was happening because org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource is an autowired field without a Qualifier and I am using multiple datasources with qualified names. I solved this problem by using @Primary arbitrarily on one of my dataSource bean configurations like so

在我的例子中,这是因为org.springframework.boot. autoconfigure.jpa.jpabaseconfigur. datasource是一个没有限定符的自动连线字段,而我使用的是具有限定名的多个数据源。我通过在我的数据源bean配置中任意使用@Primary解决了这个问题。

@Primary
@Bean(name="oneOfManyDataSources")
public DataSource dataSource() { ... }

I suppose they want you to implement AbstractRoutingDataSource, and then that auto configuration will just work because no qualifier is needed, you just have a single data source that allows your beans to resolve to the appropriate DataSource as needed. Then you don't need the @Primary or @Qualifier annotations at all, because you just have a single DataSource.

我想他们希望您实现AbstractRoutingDataSource,然后自动配置将会工作,因为不需要限定符,您只有一个数据源,它允许您的bean根据需要解析到适当的数据源。然后,您根本不需要@Primary或@Qualifier注释,因为您只有一个数据源。

In any case, my solution worked because my beans specify DataSource by qualifier, and the JPA auto config stuff is happy because it has a single primary DataSource. I am by no means recommending this as the "right" way to do things, but in my case it solved the problem quickly and did not deter the behavior of my application in any noticeable manner. Will hopefully one day get around to implementing the AbstractRoutingDataSource and refactoring all the beans that need a specific DataSource and then perhaps that will be a neater solution.

在任何情况下,我的解决方案都是有效的,因为我的bean通过限定符指定DataSource,而JPA自动配置文件很高兴,因为它有一个单独的主数据源。我并不是说这是“正确”的做事方式,但在我的情况下,它很快地解决了问题,并没有以任何明显的方式阻止我的应用程序的行为。希望有一天能够实现AbstractRoutingDataSource并重构所有需要特定数据源的bean,然后也许这将是一个更简洁的解决方案。

#7


1  

change below line of code

更改以下代码行。

spring.datasource.driverClassName

to

spring.datasource.driver-class-name

#8


1  

I was facing this issue even after supplying all required datasource properties in application.properties. Then I realized that properties configuration class was not getting scanned by Spring boot because it was in different package hierarchy compared to my Spring boot Application.java and hence no properties were applied to datasource object. I changed the package name of my properties configuration class and it started working.

即使在application.properties中提供了所有必需的数据源属性之后,我仍然面临这个问题。然后我意识到,属性配置类没有被Spring boot扫描,因为它与我的Spring引导应用程序相比,在不同的包层次结构中。java和因此没有将属性应用到datasource对象。我更改了属性配置类的包名,并开始工作。

#9


1  

If you're using application.properties in spring boot app, then just put the below line into application.properties and it should work:
spring.datasource.url: jdbc:mysql://google/?cloudSqlInstance=&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=****&password=****

如果您正在使用应用程序。在spring引导应用程序中的属性,然后将下面的行放入应用程序中。属性和它应该工作:spring.datasource。url:jdbc:mysql:/ /谷歌/ ? cloudSqlInstance = &socketFactory = com.google.cloud.sql.mysql.SocketFactory&user = * * * *密码= * * * *

#10


0  

Are you running the application as a jar? ( java -jar xxxx.jar)

您是否将应用程序作为jar运行?(java jar xxxx.jar)

If so, do you have the application.properties stored in that jar ?

如果是,您是否有应用程序。存储在那个jar中的属性?

If no, try to figure out why :

如果没有,试着找出原因:

  • To be automatically package in the jar, the files can be in : src/main/resources/application.properties
  • 要在jar中自动打包,文件可以是:src/main/resources/application.properties。
  • The maven plugin in the pom.xml can also be configured
  • pom中的maven插件。还可以配置xml。

#11


0  

It worked for me you can try your: Add this to VM options in Tomcat

它为我工作,您可以尝试:将它添加到Tomcat的VM选项中。

-DdevBaseDir="C:\Your_Project_Dir_Path"

#12


0  

In my case I just ignored the following in application.properties file:

在我的例子中,我只是忽略了应用程序中的以下内容。属性文件:

# Hibernate

#冬眠

#spring.jpa.hibernate.ddl-auto=update

# spring.jpa.hibernate.ddl-auto =更新

It works for me....

这对我来说是....

#13


0  

Check that you have database dependency at runtime group at build.gradle

在build.gradle中检查您是否有数据库依赖项。

runtime group: 'com.h2database', name: 'h2', version: '1.4.194'

or change scope from test to runtime if you use Maven

或者,如果您使用Maven,则从测试到运行时更改范围。

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

#14


0  

Give you something different, when you encounter this kind of error, cannot create bean datasource in a test case.

给您一些不同的东西,当您遇到这种错误时,不能在测试用例中创建bean数据源。

It might be caused by some reasons:

这可能是由于某些原因造成的:

  1. No datasource, you will need to create your datasource, h2 in-memory datasource or whatever, or you can choose the way like exclude={datasource··}.
  2. 没有数据源,您将需要创建您的数据源、h2内存数据源或其他任何东西,或者您可以选择排除={datasource·}。
  3. You have your datasource, like MySQL, but it still not work. It was caused by class AutoConfigureTestDatabase, It will choose a datasource for you which may cause ambiguity.
  4. 你有你的数据源,比如MySQL,但它仍然不能工作。它是由类AutoConfigureTestDatabase引起的,它会为您选择一个可能引起歧义的数据源。

Solution: add @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) to avoid replace the default datasource.

解决方案:添加@AutoConfigureTestDatabase(replace = autoconfiguretestdatabase.replace.replace . none),以避免替换默认数据源。

#1


61  

Looks like the initial problem is with the auto-config.

看起来最初的问题是自动配置。

If you don't need the datasource, simply remove it from the auto-config process:

如果您不需要数据源,只需从自动配置过程中删除它:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

#2


14  

From the looks of things you haven't passed enough data to Spring Boot to configure the datasource

从外观来看,您还没有传递足够的数据到Spring引导来配置数据源。

Create/In your existing application.properties add the following

创建/在你现有的应用程序。添加以下属性

spring.datasource.driverClassName=
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=

making sure you append a value for each of properties.

确保为每个属性追加一个值。

#3


8  

Maybe you forgot the MySQL JDBC driver.

可能忘记了MySQL JDBC驱动程序。

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.34</version>
</dependency>

#4


5  

I was getting the same error, found out it was due to some of the dependencies missing in my pom.xml like that of Spring JPA, Hibernate, Mysql or maybe jackson. So make sure that dependencies are not missing in your pom.xml and check their version compatibility.

我得到了同样的错误,发现这是由于我的pom中缺少了一些依赖项。像Spring JPA、Hibernate、Mysql或者jackson这样的xml。因此,请确保您的pom中不缺少依赖项。xml并检查它们的版本兼容性。

<!-- Jpa and hibernate -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.3.Final</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>

#5


4  

The hibernate.* properties are useless, they should be spring.jpa.* properties. Not to mention that you are trying to override those already set by using the spring.jpa.* properties. (For the explanation of each property I strongly suggest a read of the Spring Boot reference guide.

hibernate。属性是无用的,它们应该是spring.jpa.*属性。更不必说,您正在试图通过使用spring.jpa.*属性来覆盖已经设置的那些。(对于每个属性的解释,我强烈建议阅读Spring引导参考指南。

spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql = true

# Hibernate
spring.jpa.hibernate.ddl-auto=update

Also the packages to scan are automatically detected based on the base package of your Application class. If you want to specify something else use the @EntityScan annotation. Also specifying the most toplevel package isn't really wise as it will scan the whole class path which will severely impact performance.

还可以根据应用程序类的基本包自动检测包。如果您想指定其他东西,请使用@EntityScan注释。另外,指定最顶层的包并不明智,因为它会扫描整个类路径,这会严重影响性能。

#6


1  

In my case this was happening because org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource is an autowired field without a Qualifier and I am using multiple datasources with qualified names. I solved this problem by using @Primary arbitrarily on one of my dataSource bean configurations like so

在我的例子中,这是因为org.springframework.boot. autoconfigure.jpa.jpabaseconfigur. datasource是一个没有限定符的自动连线字段,而我使用的是具有限定名的多个数据源。我通过在我的数据源bean配置中任意使用@Primary解决了这个问题。

@Primary
@Bean(name="oneOfManyDataSources")
public DataSource dataSource() { ... }

I suppose they want you to implement AbstractRoutingDataSource, and then that auto configuration will just work because no qualifier is needed, you just have a single data source that allows your beans to resolve to the appropriate DataSource as needed. Then you don't need the @Primary or @Qualifier annotations at all, because you just have a single DataSource.

我想他们希望您实现AbstractRoutingDataSource,然后自动配置将会工作,因为不需要限定符,您只有一个数据源,它允许您的bean根据需要解析到适当的数据源。然后,您根本不需要@Primary或@Qualifier注释,因为您只有一个数据源。

In any case, my solution worked because my beans specify DataSource by qualifier, and the JPA auto config stuff is happy because it has a single primary DataSource. I am by no means recommending this as the "right" way to do things, but in my case it solved the problem quickly and did not deter the behavior of my application in any noticeable manner. Will hopefully one day get around to implementing the AbstractRoutingDataSource and refactoring all the beans that need a specific DataSource and then perhaps that will be a neater solution.

在任何情况下,我的解决方案都是有效的,因为我的bean通过限定符指定DataSource,而JPA自动配置文件很高兴,因为它有一个单独的主数据源。我并不是说这是“正确”的做事方式,但在我的情况下,它很快地解决了问题,并没有以任何明显的方式阻止我的应用程序的行为。希望有一天能够实现AbstractRoutingDataSource并重构所有需要特定数据源的bean,然后也许这将是一个更简洁的解决方案。

#7


1  

change below line of code

更改以下代码行。

spring.datasource.driverClassName

to

spring.datasource.driver-class-name

#8


1  

I was facing this issue even after supplying all required datasource properties in application.properties. Then I realized that properties configuration class was not getting scanned by Spring boot because it was in different package hierarchy compared to my Spring boot Application.java and hence no properties were applied to datasource object. I changed the package name of my properties configuration class and it started working.

即使在application.properties中提供了所有必需的数据源属性之后,我仍然面临这个问题。然后我意识到,属性配置类没有被Spring boot扫描,因为它与我的Spring引导应用程序相比,在不同的包层次结构中。java和因此没有将属性应用到datasource对象。我更改了属性配置类的包名,并开始工作。

#9


1  

If you're using application.properties in spring boot app, then just put the below line into application.properties and it should work:
spring.datasource.url: jdbc:mysql://google/?cloudSqlInstance=&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=****&password=****

如果您正在使用应用程序。在spring引导应用程序中的属性,然后将下面的行放入应用程序中。属性和它应该工作:spring.datasource。url:jdbc:mysql:/ /谷歌/ ? cloudSqlInstance = &socketFactory = com.google.cloud.sql.mysql.SocketFactory&user = * * * *密码= * * * *

#10


0  

Are you running the application as a jar? ( java -jar xxxx.jar)

您是否将应用程序作为jar运行?(java jar xxxx.jar)

If so, do you have the application.properties stored in that jar ?

如果是,您是否有应用程序。存储在那个jar中的属性?

If no, try to figure out why :

如果没有,试着找出原因:

  • To be automatically package in the jar, the files can be in : src/main/resources/application.properties
  • 要在jar中自动打包,文件可以是:src/main/resources/application.properties。
  • The maven plugin in the pom.xml can also be configured
  • pom中的maven插件。还可以配置xml。

#11


0  

It worked for me you can try your: Add this to VM options in Tomcat

它为我工作,您可以尝试:将它添加到Tomcat的VM选项中。

-DdevBaseDir="C:\Your_Project_Dir_Path"

#12


0  

In my case I just ignored the following in application.properties file:

在我的例子中,我只是忽略了应用程序中的以下内容。属性文件:

# Hibernate

#冬眠

#spring.jpa.hibernate.ddl-auto=update

# spring.jpa.hibernate.ddl-auto =更新

It works for me....

这对我来说是....

#13


0  

Check that you have database dependency at runtime group at build.gradle

在build.gradle中检查您是否有数据库依赖项。

runtime group: 'com.h2database', name: 'h2', version: '1.4.194'

or change scope from test to runtime if you use Maven

或者,如果您使用Maven,则从测试到运行时更改范围。

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

#14


0  

Give you something different, when you encounter this kind of error, cannot create bean datasource in a test case.

给您一些不同的东西,当您遇到这种错误时,不能在测试用例中创建bean数据源。

It might be caused by some reasons:

这可能是由于某些原因造成的:

  1. No datasource, you will need to create your datasource, h2 in-memory datasource or whatever, or you can choose the way like exclude={datasource··}.
  2. 没有数据源,您将需要创建您的数据源、h2内存数据源或其他任何东西,或者您可以选择排除={datasource·}。
  3. You have your datasource, like MySQL, but it still not work. It was caused by class AutoConfigureTestDatabase, It will choose a datasource for you which may cause ambiguity.
  4. 你有你的数据源,比如MySQL,但它仍然不能工作。它是由类AutoConfigureTestDatabase引起的,它会为您选择一个可能引起歧义的数据源。

Solution: add @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) to avoid replace the default datasource.

解决方案:添加@AutoConfigureTestDatabase(replace = autoconfiguretestdatabase.replace.replace . none),以避免替换默认数据源。