[Spring Integration] - Unabled to return specified bean factory in web application
by ivanyuan
Hi,
I am using jboss JBoss 4.2.2GA release, and want to deploy some common spring beans and make them available to all other web services or EJBs within same jboss environment.
It seems that jboss spring deployer is a good choice. I downloaded deployer version 2, then created some simple test. The MySrpingBean.spring can be deployed on jboss properly proved by the following lines in jboss log:
Bean factory [MySpringBean] binded to local JNDI
And I also saw the following information from jboss jmx-console JNDI view:
MySpringBean
org.jboss.spring.factory.NamedXmlApplicationContext
Basically, all above indicated my spring has been deployed and registered into local JDNI.
However, when I created a simple web application to retrieve it. I got the following exception:
org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [mainApplicationContext], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mainApplicationContext' is defined
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:410)
at org.springframework.web.context.ContextLoader.loadParentContext(ContextLoader.java:341)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:195)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
at org.jboss.web.WebModule.startModule(WebModule.java:83)
at org.jboss.web.WebModule.startService(WebModule.java:61)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy45.start(Unknown Source)
at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy46.start(Unknown Source)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy9.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
There is no detailed information about how to retrieve the deployed bean from web service. Not sure where I did wrong. Here is how I did.
my web.xml file is as below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:*.xml</param-value>
</context-param>
<context-param>
<param-name>parentContextKey</param-name>
<param-value>mainApplicationContext</param-value>
</context-param>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
<display-name>JAX-RS REST Servlet</display-name>
<servlet-name>JAX-RS REST Servlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<servlet-mapping>
<servlet-name>JAX-RS REST Servlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
And my spring context in web application is as below:
| <beans xmlns="http://www.springframework.org/schema/beans"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xmlns:jaxrs="http://cxf.apache.org/jaxrs"
| xmlns:aop="http://www.springframework.org/schema/aop"
| xmlns:jee="http://www.springframework.org/schema/jee"
| xsi:schemaLocation="http://www.springframework.org/schema/beans
| http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
| http://cxf.apache.org/jaxrs
| http://cxf.apache.org/schemas/jaxrs.xsd
| http://www.springframework.org/schema/aop
| http://www.springframework.org/schema/aop/spring-aop.xsd
| http://www.springframework.org/schema/jee
| http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
|
|
|
|
|
|
| <!-- retrieve spring factory MySpringBean from JNDI and it is referenced in my web.xml file -->
| <jee:jndi-lookup id="mainApplicationContext" jndi-name="MySpringBean"/>
|
| <!-- mySrpingBean is the bean reference name defined in the deployed spring context -->
|
|
|
|
|
|
|
| <jaxrs:server id="testWSEndpoint" address="/">
| <jaxrs:serviceBeans>
|
| </jaxrs:serviceBeans>
| </jaxrs:server>
|
|
|
| I'm struggling on this problem for a while. Can you please take? Any suggestion or advice will be really appreciated.
|
| Thank you in advance!
|
|
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4266663#4266663
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4266663
14 years, 11 months
[Installation, Configuration & Deployment] - Unable to re-publish war to jboss without restart (Spring 3,
by beau
Hello,
This was posted on the Spring forums, but we're not sure if it's a problem related to our project setup or jboss.. so hopefully one of these two sites can help shed some light!
We have a project using Spring 3.0.0 RC1 with Hibernate 3, running on JBoss 4.2.2.GA, and have a small but annoying issue republishing the war. Every time we do, we receive the following error and must restart the container. Once it has been restarted, it initializes everything fine. We are hoping to eliminate the task of restarting the container every time we make a change and republish.
There appears to be an issue injecting the session factory the second time around.
10:15:44,296 INFO [STDOUT] [DEBUG] 10:15:44 org.hibernate.cfg.AnnotationConfiguration - Process hbm files
| 10:15:44,296 INFO [STDOUT] [DEBUG] 10:15:44 org.hibernate.cfg.AnnotationConfiguration - Process annotated classes
| 10:15:44,296 INFO [STDOUT] [ INFO] 10:15:44 org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@10d2cf0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,disDao,trPlDao,disService,trPlService,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transactionManager]; root of factory hierarchy
| 10:15:44,312 INFO [STDOUT] [DEBUG] 10:15:44 org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'dataSource'
| 10:15:44,312 INFO [STDOUT] [ERROR] 10:15:44 org.springframework.web.context.ContextLoader - Context initialization failed
| org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'disDao' defined in file [C:\jboss\jboss-4.2.2.GA\server\default\tmp\deploy\tmp6306950577408655593PathwaysCAS-exp.war\WEB-INF\classes\main\java\com\xxxx\pcas\repository\DisDaoImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/pcas-data.xml]: Invocation of init method failed; nested exception is java.lang.reflect.UndeclaredThrowableException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/pcas-data.xml]: Invocation of init method failed; nested exception is java.lang.reflect.UndeclaredThrowableException
| at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:698)
| at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
| at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:978)
| at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:880)
| at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
| at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
| at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289)
| at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
| at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286)
| at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
| at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:543)
| at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:730)
| at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:387)
| at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:270)
| at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
| at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
| at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
| at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
| at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
| at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
| at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:597)
| at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
| at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:597)
| at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
| at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
| at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
| at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
| at org.jboss.web.WebModule.startModule(WebModule.java:83)
| at org.jboss.web.WebModule.startService(WebModule.java:61)
| at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
| ...
| ...
Below is the xml configuration:
<?xml version="1.0" encoding="UTF-8"?>
| <beans xmlns="http://www.springframework.org/schema/beans"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
| xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
| xsi:schemaLocation="http://www.springframework.org/schema/beans
| http://www.springframework.org/schema/beans/spring-beans.xsd
| http://www.springframework.org/schema/context
| http://www.springframework.org/schema/context/spring-context-2.5.xsd
| http://www.springframework.org/schema/tx
| http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
| default-autowire="byName">
|
| <!-- enable declarative transaction management -->
| <tx:annotation-driven/>
|
| <context:annotation-config/>
|
| <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
| <property name="location" value="classpath:hibernate.properties" />
| </bean>
|
| <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
| destroy-method="close">
| <property name="driverClassName" value="${hibernate.connection.driver_class}" />
| <property name="url" value="${hibernate.connection.url}" />
| <property name="username" value="${hibernate.connection.username}" />
| <property name="password" value="${hibernate.connection.password}" />
| </bean>
|
| <bean id="sessionFactory"
| class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
| <property name="dataSource" ref="dataSource" />
| <property name="packagesToScan" value="main.java.com.xxxx.pcas.entity" />
| <property name="hibernateProperties">
| <props>
| <prop key="hibernate.dialect">${hibernate.dialect}</prop>
| <prop key="hibernate.show_sql">true</prop>
| <prop key="hibernate.format_sql">true</prop>
| </props>
| </property>
| </bean>
|
| <bean id="transactionManager"
| class="org.springframework.orm.hibernate3.HibernateTransactionManager">
| <property name="sessionFactory" ref="sessionFactory" />
| </bean>
|
| </beans>
And the DisDaoImpl.java file:
@Repository("disDao")
| public class DisDaoImpl extends AbstractHibernateDao<Dis> implements DisDao {
|
| @Autowired
| public DisDaoImpl(SessionFactory sessionFactory) {
| super(Dis.class, sessionFactory);
| }
|
| public Dis findById(Short id) {
| return get(id);
| }
|
| public List<Dis> findAll() {
| return all();
| }
|
| public void save(Dis dis) {
| currentSession().saveOrUpdate(dis);
| }
|
| public void delete(Dis dis) {
| currentSession().delete(dis);
| }
|
| }
If there is any other information I can provide that might help out, just let me know.
Thanks for your time,
Beau
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4266658#4266658
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4266658
14 years, 11 months