Hello All,
I'm not sure if it's just gotten too late at night and I can't think straight, but I'm having a problem getting non-singleton beans from the IoC container.
I'm still in the testing phase of my Spring learning, but I'm starting to apply it to a real project and I am running into this issue.
Here's part of my web.xml:
My applicationContext.xml looks like this. (I changed the bean id and class names.)Code:<context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/dataAccessContext.xml /WEB-INF/applicationContext.xml </param-value> </context-param> <servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>ServletName</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
I am using the Spring Web MVC and here is my ServletName-servlet.xml file:Code:<bean id="beanOne" class="example.beanOne" singleton="false"/> <bean id="beanTwo" class="example.beanTwo" singleton="false" init-method="init"> <property name="beanOne"> <ref bean="beanOne"/> </property> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean>
I put System.out.println in the constructors of beanOne and beanTwo. I reload the page and watch the command line. I only see the constructors for beanOne and beanTwo fire off once. Each time after that I get other messages I'm outputting, but not those bean's constructors.Code:<beans> <!-- Type of view to produce --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> <property name="prefix"><value>/WEB-INF/jsp/</value></property> <property name="suffix"><value>.jsp</value></property> </bean> <bean id="stuffController" class="example.web.StuffController"> <property name="beanTwo"> <ref bean="beanTwo"/> </property> </bean> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/showStuff.action">stuffController</prop> </props> </property> </bean> </beans>
I haven't written any code that accesses any part of the Spring API. All the code I've written just uses my bean's methods.
Any help would be appreciated.
Thanks!


Reply With Quote