简体   繁体   English

无法从 org.springframework.orm.hibernate5.LocalSessionFactoryBean 实例化 sessionFactory

[英]Failed to instantiate sessionFactory From org.springframework.orm.hibernate5.LocalSessionFactoryBean

We are using spring and hibernate in our application i create LocalSessionFactoryBean object then @autowire SessionFactory in Repository As Follow : Create LocalSessionFactoryBean in AppConfig我们在我们的应用程序中使用 spring 和 hibernate 我创建 LocalSessionFactoryBean 对象然后在 Repository 中 @autowire SessionFactory 如下:在 AppConfig 中创建 LocalSessionFactoryBean

 @EnableCaching
 @EnableAsync
 @EnableTransactionManagement
 @Configuration
 class AppCOnfig extends WebMvcConfigurerAdapter{
 @Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(restDataSource());
    sessionFactory.setPackagesToScan("com.xx.yyy");
    sessionFactory.setHibernateProperties(hibernateProperties());
    sessionFactory.setPhysicalNamingStrategy(new SnakeCaseNamingStrategy());
    sessionFactory.setImplicitNamingStrategy(new ImplicitNamingStrategyLegacyHbmImpl());
    return sessionFactory;
  }
}

In Repository We are Using @autowire annotation as在存储库中,我们使用 @autowire 注释作为

@Slf4j
@Repository
public class UserRepository {

    @Autowired
    private SessionFactory sessionFactory;

}

We are using hibernate and spring version as below : 4.3.4.RELEASE 5.2.10.Final But when i start application i got this error :我们正在使用 hibernate 和 spring 版本如下: 4.3.4.RELEASE 5.2.10.Final 但是当我启动应用程序时,我收到了这个错误:

Error creating bean with name 'sessionFactory' defined in XXX.AppConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.hibernate5.LocalSessionFactoryBean]: Factory method 'sessionFactory' threw exception; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.EnumConstantNotPresentExceptionProxy
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)

I knew there is some issue when spring tried to got session factory from localeSessionFactoryBean But can not figure out how can we solve it.If anyone have some idea about it please help me out.我知道当 spring 试图从 localeSessionFactoryBean 获取会话工厂时存在一些问题,但无法弄清楚我们如何解决它。如果有人对此有所了解,请帮助我。

An EnumConstantNotPresentException is thrown when something tries to reference an enum constant by name when it doesn't exist. EnumConstantNotPresentException当某物试图通过名称引用不存在的枚举常量时,会抛出EnumConstantNotPresentException The Proxy variant of it is thrown, in my experience, when there's reflection involved.根据我的经验,当涉及反射时,会抛出它的Proxy变体。 If you debug your app with a breaking point on the EnumConstantNotPresentExceptionProxy(Class<? extends Enum<?>>, String) constructor, you should be able to see the class of the enum and the name of the non-existent constant.如果您在EnumConstantNotPresentExceptionProxy(Class<? extends Enum<?>>, String)构造函数上使用EnumConstantNotPresentExceptionProxy(Class<? extends Enum<?>>, String)调试您的应用程序,您应该能够看到枚举的类和不存在的常量的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法找到名为“hibernate5AnnotatedSessionFactory”的 bean 的类 [org.springframework.orm.hibernate5.LocalSessionFactoryBean] - Cannot find class [org.springframework.orm.hibernate5.LocalSessionFactoryBean] for bean with name 'hibernate5AnnotatedSessionFactory' 如何从 org.springframework.orm.hibernate4.LocalSessionFactoryBean 获取 Hibernate SessionFactory? - How to get the Hibernate SessionFactory from org.springframework.orm.hibernate4.LocalSessionFactoryBean? 在 springORM 中声明 org.springframework.orm.hibernate5.LocalSessionFactoryBean 的 bean 显示错误 - Declaring bean of org.springframework.orm.hibernate5.LocalSessionFactoryBean in springORM is showing error org.springframework.orm.hibernate4.LocalSessionFactoryBean无法转换为org.hibernate.SessionFactory - org.springframework.orm.hibernate4.LocalSessionFactoryBean cannot be cast to org.hibernate.SessionFactory 找不到类&#39;org.springframework.orm.hibernate4.LocalSessionFactoryBean&#39; - Class 'org.springframework.orm.hibernate4.LocalSessionFactoryBean' not found Java、Spring、Hibernate 找不到 org.springframework.orm.hibernate3.LocalSessionFactoryBean - Java, Spring, Hibernate cannot find org.springframework.orm.hibernate3.LocalSessionFactoryBean spring 迁移 4 到 5; 是什么导致 java.lang.ClassNotFoundException:org.springframework.orm.hibernate4.LocalSessionFactoryBean - spring migration 4 to 5; what is causing java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean 找不到名为&#39;sessionFactory&#39;的bean的类[org.springframework.orm.hibernate3.annotation.AnnotationSessionFactory] - Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactory] for bean with name 'sessionFactory' 找不到名称为&#39;sessionFactory&#39;的bean的类[org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] - Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for bean with name 'sessionFactory' BeanInstantiationException:无法实例化[org.hibernate.SessionFactory]:涉及包含bean的循环引用 - BeanInstantiationException: Failed to instantiate [org.hibernate.SessionFactory]: Circular reference involving containing bean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM