I am a beginner with Spring,
I have a web application (in a Jetty webapp), my web.xml indicates where to find the applicationContext.xml to Jetty. It works.
But I would like to get the bean factory in my java code.
When I hadn't the webapp and had only Junit tests I had something like :
but now I work in Jetty I would like to get the already instantiated by Jetty bean factory.Code:ClassPathResource res = new ClassPathResource("applicationContext.xml"); springFactory = new XmlBeanFactory(res);
I searched for some static methods but didn't find.
Thanks for replies.
Here is a part of my xeb.xml file :
And a part of my applicationContext.xml file :Code:<web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/WEB-INF/applicationContext.xml</param-value> </context-param> </web-app>
Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:configurator="http://cocoon.apache.org/schema/configurator" xmlns:avalon="http://cocoon.apache.org/schema/avalon" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.xsd http://cocoon.apache.org/schema/avalon http://cocoon.apache.org/schema/avalon/cocoon-avalon-1.0.xsd"> <!-- Activate Cocoon Spring Configurator --> <configurator:settings /> <!-- Configure Log4j --> <bean name="org.apache.cocoon.spring.configurator.log4j" class="org.apache.cocoon.spring.configurator.log4j.Log4JConfigurator" scope="singleton"> <property name="settings" ref="org.apache.cocoon.configuration.Settings" /> <property name="resource" value="/WEB-INF/log4j.xml" /> </bean> <!-- Activate Avalon Bridge --> <avalon:bridge /> <bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/metadatadb" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="myDataSource" /> <property name="configLocation"> <value>classpath:/hibernate.cfg.xml</value> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="storageInitializer" class="xxx.StorageInitializer"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> </beans>


Reply With Quote