Hello All,
I am trying to port our application to JBoss 7 and am having issues getting Spring 2.5 autowiring working. I found that if I declare my bean manually in XML, I can see them being registered correctly. If I rely on component-scan, Spring says it's initializing Spring, but not my beans. Any tips on debugging this?
Thanks in advance,
Steven
PS - I just tested this in Spring 3.0 and it works exactly as expected. However, the application I am porting is huge and moving to Spring 3.0 would be a non-trivial investment, so we'd love to get it working in 2.5 for now.
Here's my Spring config - applicationContext.xml
Here's my web.xmlCode:<?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: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-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- Activates annotation-based bean configuration --> <context:annotation-config /> <!-- Fails...never appears to be run. --> <context:component-scan base-package="com.mycompany" /> <!-- Works when uncommented. --> <!-- <bean class="com.mycompany.ChatterBox"/> --> </beans>
Here's the bean in question.Code:<web-app 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_3_0.xsd" version="3.0"> <description>Our canary in a coal mine - Can we get Spring working?</description> <display-name>BareBones</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> </web-app>
Code:package com.mycompany; import java.util.Date; import javax.annotation.PreDestroy; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Component; /** * Tracing class designed to output when constructed. */ @Component public class ChatterBox { private final Log logger = LogFactory.getLog(getClass()); public ChatterBox() { //we want this to be very visible and easy to read. logger.fatal("\n\n\n\n\nSingleton was constructed at " + new Date() + " (you should only see me once)\n\n\n\n"); if(true){//to avoid compiler error, RuntimeException used to get indisputable proof this was run. throw new RuntimeException("Did I get run?"); } } @PreDestroy protected void finalize2(){ logger.warn("\n\nI was destroyed by @PreDestory on " + new Date() + "\n\n"); } }


Reply With Quote
