上下文初始化失败——BeanCreationNotAllowedException
我的应用程序的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.就我而言,我在 2.5.0 版本中遇到了同样的问题,但那是我的错。
我在上下文中使用了错误的bean。
详细来说:我有 Spring MVC 控制器(名为 OrderController),用
@Controller
注释,没有定义名称(注释驱动)。另一方面,CXF 需要 xml 配置 AFAIK,所以我使用 java 配置(使用@Bean
)将 bean 命名为orderController
,并且在初始化 cxf 时,Spring 使用了这个错误的 MVC 控制器,并且它因上面列出的错误而失败。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
) asorderController
and somehow when cxf was initialized Spring used this wrong MVC controller and it failed on error listed above.