上下文初始化失败——BeanCreationNotAllowedException

发布于 2024-12-05 18:35:41 字数 1264 浏览 2 评论 0原文

我的应用程序的 Spring 上下文无法初始化。谁能帮助我理解它为什么失败以及如何修复它?

以下是警告和信息:我收到的错误消息:

[警告] 在 bean 上调用销毁方法“shutdown”失败 名称“cxf”

org.springframework.beans.factory.BeanCreationNotAllowedException: 创建名称为“entityManagerFactory”的 bean 时出错:单例 bean 当该工厂的单例处于状态时不允许创建 销毁(不要在销毁过程中从 BeanFactory 请求 Bean) 方法实现!)

org.springframework.web.context.ContextLoader [错误]上下文初始化失败

<bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl" destroy-method="shutdown"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
       <property name="persistenceUnitName" value="${persistence.unit}"/>
       <property name="dataSource" ref="pooledDs"/>
       <property name="jpaVendorAdapter">
           <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
               <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="showSql" value="false"/>
               <property name="generateDdl" value="false"/>
           </bean>
       </property>    
</bean> 

The Spring Context of my application is failing to initialize. Can anyone help me understand why it is failing and how to fix it?

Below are the warning & error messages I'm getting:

[WARN] Invocation of destroy method 'shutdown' failed on bean with
name 'cxf'

org.springframework.beans.factory.BeanCreationNotAllowedException:
Error creating bean with name 'entityManagerFactory': Singleton bean
creation not allowed while the singletons of this factory are in
destruction (Do not request a bean from a BeanFactory in a destroy
method implementation!)

org.springframework.web.context.ContextLoader
[ERROR] Context initialization failed

<bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl" destroy-method="shutdown"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
       <property name="persistenceUnitName" value="${persistence.unit}"/>
       <property name="dataSource" ref="pooledDs"/>
       <property name="jpaVendorAdapter">
           <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
               <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="showSql" value="false"/>
               <property name="generateDdl" value="false"/>
           </bean>
       </property>    
</bean> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开柳相依 2024-12-12 18:35:41

CXF 网站的示例配置中不包含 destroy-method 调用,因此这似乎是一个错误配置。有关详细信息,请参阅此页面:http://cxf.apache.org/docs/interceptors.html。

我还找到了针对此问题的错误跟踪器: https://issues.apache.org/jira /浏览/CXF-2164。看来,destroy 方法在 CXF 的早期版本中并未被隐式调用,但在 v2.2.11 中已修复。

因此,我的建议是至少达到该版本,并且只需在您的中添加 配置。

The CXF website doesn't include the destroy-method call in its example configurations, so it seems like this is a misconfiguration. See this page for details: http://cxf.apache.org/docs/interceptors.html.

I also found a bug tracker for this issue: https://issues.apache.org/jira/browse/CXF-2164. It appears that the destroy method was not implicitly being called in earlier versions of CXF, but that has been fixed in v2.2.11.

So, my suggestion would be to get up to at least that version and just have <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl" /> in your config.

夏夜暖风 2024-12-12 18:35:41

就我而言,我在 2.5.0 版本中遇到了同样的问题,但那是我的错。

我在上下文中使用了错误的bean。

详细来说:我有 Spring MVC 控制器(名为 OrderController),用 @Controller 注释,没有定义名称(注释驱动)。另一方面,CXF 需要 xml 配置 AFAIK,所以我使用 java 配置(使用 @Bean)将 bean 命名为 orderController ,并且在初始化 cxf 时,Spring 使用了这个错误的 MVC 控制器,并且它因上面列出的错误而失败。

org.springframework.beans.factory.BeanCreationNotAllowedException:创建名称为“cxf”的bean时出错:当该工厂的单例处于销毁状态时,不允许创建单例bean(不要在销毁方法实现中从BeanFactory请求bean !)

In my case I had same problem with version 2.5.0, but that was my fault.

I had wrong bean in context.

In detail: I had Spring MVC Controller (named OrderController) annotated with @Controller without defined name (annotation driven). On the other CXF requires xml configuration AFAIK, so I named bean using java configuration (using @Bean) as orderController and somehow when cxf was initialized Spring used this wrong MVC controller and it failed on error listed above.

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'cxf': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文