我想配置一个Spring Boot应用程序来使用ObjectDB持久性而不是默认的Hibernate,但是我不能这样做。由于ObjectDB已经是一个JPA提供程序,我需要排除任何涉及DataSource、JDBC或Hibernate的自动配置。
到目前为止,我有以下申请。爪哇:
@Configuration
@EnableAutoConfiguration(exclude={HibernateJpaAutoConfiguration.class})
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
@Primary
public EntityManagerFactory entityManagerFactory() {
return Persistence.createEntityManagerFactory("test.odb");
}
}
建造。格雷德尔:
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude module: 'hibernate-entitymanager' //by artifact name
}
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile('com.objectdb:objectdb:2.6.5')
compile('org.eclipse.persistence:javax.persistence:2.1.0')
}
但是,当使用以下异常摘录启动应用程序时,这将失败:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourcePublicMetrics': Invocation of init method failed; 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]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method '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.
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:996)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 134 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method '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.
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:217)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:350)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
at org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics.getPrimaryDataSource(DataSourcePublicMetrics.java:119)
at org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics.initialize(DataSourcePublicMetrics.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 146 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method '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.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 166 more
Caused by: 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.
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:137)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 167 more
Spring Boot似乎试图创建一个“PublicMetrics”bean,该bean包含有关数据源的信息,但未能创建数据源,因为ObjectDB是一个面向对象的数据库,而不是SQL数据库,所以它不提供任何数据源。
如何完全禁用PublicMetrics?
我已经试过了http://www.objectdb.com/database/forum/860如果没有成功,并且我从依赖项中排除了“spring boot starter jdbc”,那么出于某种原因,我的spring数据存储库不会被实例化。
不过,我发现我只需要排除jdbc依赖项,并显式添加@EnableJpaRepositories注释就可以让存储库正常工作。
下面是工作配置:
一个pplication.java
@SpringBootApplication
@EnableJpaRepositories // Needed when using objectdb
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
// Needed when using objectdb
@Bean
public EntityManagerFactory entityManagerFactory() {
return Persistence.createEntityManagerFactory("test.odb");
}
// Needed when using objectdb
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager(entityManagerFactory());
}
}
build.gradle:
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-tomcat')
// Needed to exclude these when using objectdb
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude module: 'spring-boot-starter-jdbc' //by artifact name
exclude module: 'hibernate-entitymanager' //by artifact name
}
compile('com.objectdb:objectdb:2.6.5')
compile('org.eclipse.persistence:javax.persistence:2.1.0')
}
我正在尝试将vaadin与spring(没有Spring Boot)和基于java注释的spring部分配置结合起来。 自动连接似乎适用于vaadin ui部分,但不适用于“自定义ui类”(例如,“公共类LoginScreen扩展自定义组件”)。我在SysOut上得到一个NPE或一个空对象。 此外,我注意到“@ComponentScan(base Packages={"net.myapp"})”没
问题内容: 我必须在SpringBoot应用程序中使用@PathValiable从URL获取参数。这些参数通常带有 斜线 。我无法控制用户在URL中输入的内容,因此我想获取他输入的内容,然后我就可以对其进行处理。 我已经在这里浏览过材料和答案,我认为对我而言,好的解决方案不是要求用户以某种方式对输入的参数进行编码。 SpringBoot代码很简单: 因此,URL如下所示: 问题在于,参数 modu
我必须在SpringBoot应用程序中使用@PathValiable从URL获取参数。这些参数通常有斜线。我没有一个关于用户将输入URL的控制,所以我想要得到他输入的内容,然后我可以处理它。 我已经看过了这里的资料和答案,我不认为对我来说,好的解决方案是要求用户以某种方式编码输入参数。
有没有办法绕过授权?
在下面的代码中,我有时会将设置为null。此时,它抛出错误为“could not extract resultset;SQL[n/a];嵌套异常为org.hibernate.exception.sqlgrammarexception:could not extract resultset” 即使为空,我如何获取数据。总有一天约会就要来了。这是怎么做的? null
我正在自己配置Spring Boot应用程序,以运行两个数据库(两个transactionManager相同)。MariaDB和MongoDb。在@Repository中,我已经用@PersistenceContext使用了@Autowired,注释@Transactional正在正确地使用TransactionManager。但对我来说,最有用的是在@Services层上添加@Transacio
我试图编写一个方法,它接受@PathVariable参数,并将用户重定向到一个jsp文件。 @pathvariable(value=“customerId”)字符串customerId @pathvariable(name=“customerId”)字符串customerId @pathvariable(“customerId”)字符串customerId 谢谢你的帮助。
我有这个目标: 还有这个: