Hello to all, I have configure Spring to autowired my dao object into servlet but it return null. Anyone know why?
web.xml
applicationContext.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>BISApp</display-name> <listener> <listener-class>com.breeze.bis.app.listener.VBossContextListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>applicationContext.xml</param-value> </context-param> <listener> <display-name>contextLoaderListener</display-name> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>compress</filter-name> <filter-class>com.breeze.web.commons.filters.CompressionFilter</filter-class> </filter> <filter-mapping> <filter-name>compress</filter-name> <url-pattern>*.view</url-pattern> <url-pattern>*.get</url-pattern> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter> <filter-name>hibernateFilter</filter-name> <filter-class> com.breeze.bis.app.filters.BISHibernateSessionFilter </filter-class> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.view</url-pattern> <url-pattern>*.get</url-pattern> </filter-mapping> <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <display-name>AuthFilter</display-name> <filter-name>AuthFilter</filter-name> <filter-class>com.breeze.bis.app.filters.BISAuthFilter</filter-class> </filter> <filter-mapping> <filter-name>AuthFilter</filter-name> <url-pattern>*.get</url-pattern> <url-pattern>*.view</url-pattern> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter> <display-name>CacheFilter</display-name> <filter-name>CacheFilter</filter-name> <filter-class>com.breeze.web.commons.filters.CacheFilter</filter-class> </filter> <filter-mapping> <filter-name>CacheFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <display-name>AppController</display-name> <servlet-name>AppController</servlet-name> <servlet-class>com.breeze.bis.app.servlets.BISAppController</servlet-class> <load-on-startup></load-on-startup> </servlet> <servlet-mapping> <servlet-name>AppController</servlet-name> <url-pattern>/app.view</url-pattern> <url-pattern>/app.get</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>AuthServlet</display-name> <servlet-name>AuthServlet</servlet-name> <servlet-class>com.breeze.bis.app.servlets.BISAuthServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>AuthServlet</servlet-name> <url-pattern>/auth.view</url-pattern> <url-pattern>/admin/auth.view</url-pattern> </servlet-mapping> <session-config> <session-timeout>60</session-timeout> </session-config> <servlet> <description></description> <display-name>GetCustomerAddImage</display-name> <servlet-name>GetCustomerAddImage</servlet-name> <servlet-class>com.breeze.bis.app.servlets.GetCustomerAddImage</servlet-class> </servlet> <servlet-mapping> <servlet-name>GetCustomerAddImage</servlet-name> <url-pattern>/GetCustomerAddImage</url-pattern> </servlet-mapping> </web-app>
ServletCode:<?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" 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"> <context:annotation-config /> <context:component-scan base-package="com.breeze.bis.core.service.jdbcTemplate" /> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/vbossdb" /> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="user" value="root" /> <property name="password" value="root" /> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <constructor-arg type="javax.sql.DataSource" ref="dataSource"></constructor-arg> </bean> <bean id="genericDaoImpl" class="com.breeze.bis.core.service.jdbcTemplate.GenericDAOImpl"> <property name="jdbcDao" ref="jdbcTemplate"></property> </bean> <!-- This will automatically locate any and all property files you have within your classpath, provided they fall under the META-INF directory. The located property files are parsed and their values can then be used within application context files in the form of ${propertyKey}. --> <!-- <context:property-placeholder location="classpath*:*.properties" /> --> <!-- This declaration will cause Spring to locate every @Component, @Repository and @Service in your application. In practical terms this allows you to write a POJO and then simply annotate the new POJO as an @Service and Spring will automatically detect, instantiate and dependency inject your service at startup time. Importantly, you can then also have your new service injected into any other class that requires it simply by declaring a field for your service inside the relying class and Spring will inject it. Note that two exclude filters are declared. The first ensures that Spring doesn't spend time introspecting Roo-specific ITD aspects. The second ensures Roo doesn't instantiate your @Controller classes, as these should be instantiated by a web tier application context. Refer to web.xml for more details about the web tier application context setup services. Furthermore, this turns on @Autowired, @PostConstruct etc support. These annotations allow you to use common Spring and Java Enterprise Edition annotations in your classes without needing to do any special configuration. The most commonly used annotation is @Autowired, which instructs Spring to dependency inject an object into your class. --> <!-- <context:component-scan base-package="sk.funix.userstory"> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" /> </context:component-scan> <import resource="applicationContext-infrastructure.xml" /> <import resource="applicationContext-aop.xml" /> <import resource="applicationContext-security.xml" /> --> </beans>
Code:public class UnknownTroubleTicketViewTask extends AbstractTask { @Autowired GenericDAO dao;
What is the reason? Please help. Thanks.


Reply With Quote
