Spring Boot 2.2 多模块项目自动配置 JPA 失败

huangapple go评论75阅读模式
英文:

Spring Boot 2.2 Multi Module Project auto configuration JPA failed

问题

I have a Spring-Boot multimodule Project.
Main Module is a Vaadin Web-App (at the Moment very simple) and a second Module called Login with Spring Entitys, Repository and Service bean.

In the Login Module I have written Testcode that runs against a H2 Database. Tests are green, Entity was created, repository exists and so on. (Everything fine)

When I try to start the WebApp I always get the Message

A component required a bean named 'entityManagerFactory' that could not be found.

My Main Application Class

@SpringBootApplication(scanBasePackages = "eu.dwich.btc", exclude = ErrorMvcAutoConfiguration.class)
@Import(BtcBackendLoginConfig.class)
public class Application extends SpringBootServletInitializer {

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

}

Then my Config Class in the module

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(basePackageClasses = BtcBackendLoginConfig.class)
@EntityScan(basePackageClasses = BtcBackendLoginConfig.class)
@EnableJpaRepositories(basePackageClasses = BtcBackendLoginConfig.class)
public class BtcBackendLoginConfig {
}

and the properties file

database.driver-class-name=org.postgresql.Driver
database.database-url=jdbc:postgresql://localhost:5433/btc_dev
database.database-user=btc_dev
database.database-user-password=xxxxx
# --------------------------------------
# special DB settings
database.hibernater-format-s-q-l=true
database.hibernater-gen-statistics=true
database.hibernate-dialect=org.hibernate.dialect.PostgreSQL9Dialect
# possible: create-drop, none, validate, update, create
database.hibernate-ddl-auto=create-drop
database.create-db-script=true

First (maybe simple) Question, where should I put the application.properties to configure the database, in the web Project or in the Login module?

Second Question what I'm doing wrong? is it not possible to get the spring boot auto-configuration to work? (I don't want to configure datasource and entity manager)

I have tried a lot of different configurations nothing worked until now.

Thanks in advance

Update 1:
there is only one line with a warning, no other stack trace

2020-09-24 08:07:34.788  INFO 19699 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: Ant [pattern='/h2-console/**'], []
2020-09-24 08:07:34.802  INFO 19699 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@b246c96, org.springframework.security.web.context.SecurityContextPersistenceFilter@f632a44, org.springframework.security.web.header.HeaderWriterFilter@3bd390ec, org.springframework.security.web.authentication.logout.LogoutFilter@44e09d5a, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@30d21b64, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@1eed7157, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1d1c15ef, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@15a14e1e, org.springframework.security.web.session.SessionManagementFilter@6a47a0c5, org.springframework.security.web.access.ExceptionTranslationFilter@5492fd4, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@4f5c34f5]
2020-09-24 08:07:34.825  WARN 19699 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - canceling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userGroupRepository': Cannot create inner bean '(inner bean)#542c45c7' 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)#542c45c7': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2020-09-24 08:07:34.827  INFO 19699 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

At the end there is only this message, is it possible to get more information?

2020-09-24 08:07:34.887 ERROR 19699 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'entityManagerFactory' that could not be found.


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.


Process finished with exit code 0

Update:
This output will be generated when turning debug on:

Exclusions:
-----------

    org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

    org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration

    org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

    org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

    org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration

    org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

    org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:805) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1278) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:680) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:498) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowire

<details>
<summary>英文:</summary>

I have a Spring-Boot multimodule Project.
Main Module is a Vaadin Web-App (at the Moment very simple) and a second Module called Login with Spring Entitys, Repository and Service bean.

In the Login Module I have written Testcode that runs against a H2 Database. Tests are green, Entity was created, repository exists and so on. (Everything fine)

When I try to start the WebApp I allways get the Message 

&gt; A component required a bean named &#39;entityManagerFactory&#39; that could not be found.

My Main Applicattion Class

@SpringBootApplication(scanBasePackages = "eu.dwich.btc", exclude = ErrorMvcAutoConfiguration.class)
@Import(BtcBackendLoginConfig.class)
public class Application extends SpringBootServletInitializer {

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

}

Then my Config Class in the module

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(basePackageClasses = BtcBackendLoginConfig.class)
@EntityScan(basePackageClasses = BtcBackendLoginConfig.class)
@EnableJpaRepositories(basePackageClasses = BtcBackendLoginConfig.class)
public class BtcBackendLoginConfig {
}

and the properties file

database.driver-class-name=org.postgresql.Driver
database.database-url=jdbc:postgresql://localhost:5433/btc_dev
database.database-user=btc_dev
database.database-user-password=xxxxx

--------------------------------------

special DB settings

database.hibernater-format-s-q-l=true
database.hibernater-gen-statistics=true
database.hibernate-dialect=org.hibernate.dialect.PostgreSQL9Dialect

possible: create-drop, none, validate, update, create

database.hibernate-ddl-auto=create-drop
database.create-db-script=true


First (maybe simple) Question, where should I put the application.properties to configure the database, in the web Project or in the Login module?

Second Question what I&#39;m doing wrong? is it not possible to get the spring boot autoconfiguration to work? (I don&#39;t whant to configure datasource and entitymanager)

I have tryed a lot of different configrurations nothing worked until now.

Thanks in advance

Update 1:
there is only one line with a warning, no other stacktrace


2020-09-24 08:07:34.788 INFO 19699 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: Ant [pattern='/h2-console/**'], []
2020-09-24 08:07:34.802 INFO 19699 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@b246c96, org.springframework.security.web.context.SecurityContextPersistenceFilter@f632a44, org.springframework.security.web.header.HeaderWriterFilter@3bd390ec, org.springframework.security.web.authentication.logout.LogoutFilter@44e09d5a, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@30d21b64, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@1eed7157, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1d1c15ef, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@15a14e1e, org.springframework.security.web.session.SessionManagementFilter@6a47a0c5, org.springframework.security.web.access.ExceptionTranslationFilter@5492fd4, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@4f5c34f5]
2020-09-24 08:07:34.825 WARN 19699 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userGroupRepository': Cannot create inner bean '(inner bean)#542c45c7' 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)#542c45c7': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2020-09-24 08:07:34.827 INFO 19699 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]

At the end ther is only this message, is it possible to get more information?

2020-09-24 08:07:34.887 ERROR 19699 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

A component required a bean named 'entityManagerFactory' that could not be found.

Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

Process finished with exit code 0


Update: 
This output will be generated when turning debug on:

Exclusions:

org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration

org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration

org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:805) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1278) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:680) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:498) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:374) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:134) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1451) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:860) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at eu.dwich.btc.Application.main(Application.java:24) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.2.0.RELEASE.jar:2.2.0.RELEASE]

why does spring exclude the whole spring Data stack??

</details>


# 答案1
**得分**: 1

你使用了错误的变量键,因此Spring无法配置所需的对象。

改为使用以下内容:

```properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5433/btc_dev
spring.datasource.username=btc_dev
spring.datasource.password=xxxxx

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format-sql=true
spring.jpa.properties.hibernate.generate_statistics=true
spring.jpa.database=postgresql
spring.jpa.hibernate.dll-auto=create-drop

另外,请确保类路径上有所有所需的库。您至少需要 javax.persistence-apihibernate

我还建议您不要使用 basePackageClasses,除非您知道它的作用。如果您将应用程序配置放在其自己的包中而不是根目录下,Spring将无法找到任何符合条件的类。
至少目前,请改为使用 basePackages = "eu.dwich.btc"

这里有一个常见的Spring属性列表。
在 # DATASOURCE 部分旁边,您会看到对 DataSourceAutoConfiguration 的引用。

英文:

You use the wrong variable keys so Spring cannot configure the objects required.

Instead, use the following

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5433/btc_dev
spring.datasource.username=btc_dev
spring.datasource.password=xxxxx

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format-sql=true
spring.jpa.properties.hibernate.generate_statistics=true
spring.jpa.database=postgresql
spring.jpa.hibernate.dll-auto=create-drop

Also, make sure you have all the required libraries on the classpath.
You need at least javax.persistence-api and hibernate.

I would also advice you NOT to use basePackageClasses unless you know what it does. If you place your Application configuration in his own package instead of the root, Spring won't be able to find any eligible classes.
At least for now, use basePackages = &quot;eu.dwich.btc&quot; instead.

Here is a list of common Spring properties.
Next to the # DATASOURCE section you see the reference to DataSourceAutoConfiguration.

答案2

得分: 0

检查您的pom文件,您必须缺少一些依赖项。我之前也遇到过相同的问题,在仔细查看了pom文件后解决了,缺少了PostgreSQL驱动jar包和spring-data依赖。它会显示非常常见的错误,您应该启用堆栈跟踪
"server.error.include-stacktrace=never"
以获取更详细的错误信息。

英文:

Check your pom file , you must be missing some dependencies. I was also same problem and resolved after carefully gone through pom file , posgress driver jar was missing and spring-data depenndency was missing. Its giving very generic error you should enable stack trace
"server.error.include-stacktrace=never"
to get more detailed error.

答案3

得分: -1

我认为我找到了错误。

  1. 简单的Spring应用程序,没有导入
@SpringBootApplication(scanBasePackages = "eu.dwich.btc", exclude = ErrorMvcAutoConfiguration.class)
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
  1. 后端配置需要一些修改
@Configuration
@EnableTransactionManagement
@EntityScan(basePackages = "eu.dwich.btc")
@EnableJpaRepositories(basePackages = "eu.dwich.btc")
@Import({
    DataSourceAutoConfiguration.class,
    HibernateJpaAutoConfiguration.class,
    DataSourceTransactionManagerAutoConfiguration.class })
@Profile("!test")
public class BtcBackendLoginConfig {
}

第二个 @SpringBootApplication 是一个错误,不需要它。
没有自动配置导入,它将无法工作。

并且要小心属性,就是这样......

#spring.jpa.properties.hibernate.ddl-auto=create-drop 是错误的
#spring.jpa.hibernate.hbm2ddl.auto=create-drop 也是错误的
# 正确的(正如Nico Van Belle所提到的)是:
spring.jpa.hibernate.ddl-auto=create-drop

如果你运行一个真实的数据库(不是H2),默认的 ddl-auto= 是 none。

在我看来,导入自动配置类不是最好的方法,但它可以工作。

英文:

I think I found the error

  1. Spring applikation simple without imports
@SpringBootApplication(scanBasePackages = &quot;eu.dwich.btc&quot;, exclude = ErrorMvcAutoConfiguration.class)
public class Application extends SpringBootServletInitializer {

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

}
  1. the backend config needs some modifikation
@Configuration
@EnableTransactionManagement
@EntityScan(basePackages = &quot;eu.dwich.btc&quot;)
@EnableJpaRepositories(basePackages = &quot;eu.dwich.btc&quot;)
@Import({
    DataSourceAutoConfiguration.class,
    HibernateJpaAutoConfiguration.class,
    DataSourceTransactionManagerAutoConfiguration.class })
@Profile(&quot;!test&quot;)
public class BtcBackendLoginConfig {
}

the second @SpringBootApplication was an error and is not needet
without the Autoconfig imports it won't work

and be carefull with the properties, tada.....

#spring.jpa.properties.hibernate.ddl-auto=create-drop is wrong
#spring.jpa.hibernate.hbm2ddl.auto=create-drop is also wrong
# the right one (as mentioned by Nico Van Belle) is: 
spring.jpa.hibernate.ddl-auto=create-drop 

and if your run an real database (not H2) the default ddl-auto= is none

In my opinion the import of the autoconfig classes is not the best way, but it works.

huangapple
  • 本文由 发表于 2020年9月21日 22:25:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/63994284.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定