向service里面注入dao。为什么注入不进?有空的帮个忙看看。
就是在下面service里面,发觉userDao为null.为什么不能注入呢?兄弟们帮帮忙看看。
public class LoginServiceImpl implements LoginService {
private UserDAO userDao;
public void setUserDao(UserDAO userDao) {
this.userDao = userDao;
}
public User findUserById(String userId) {
User user = userDao.findUserById(userId);
return user;
}
}
applicationContext.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN " "http://www.springframework.org/dtd/spring-beans.dtd ">
<beans default-autowire= "byName ">
<bean id= "sessionFactory " class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property name= "configLocation ">
<value> classpath:hibernate.cfg.xml </value>
</property>
</bean>
<bean id= "loginAction " class= "freeunite.action.LoginAction " />
<bean id= "logoutAction " class= "freeunite.action.LogoutAction " />
<bean id= "userDao " class= "freeunite.dao.UserDAOImpl " singleton= "false ">
<property name= "sessionFactory ">
<ref bean= "sessionFactory " />
</property>
</bean>
web.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app xmlns= "http://java.sun.com/xml/ns/j2ee "
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " version= "2.4 "
xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<filter>
<filter-name> encodingFilter </filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name> encoding </param-name>
<param-value> UTF-8 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name> encodingFilter </filter-name>
<url-pattern> /* </url-pattern>
</filter-mapping>
<filter>
<filter-name> hibernateFilter </filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name> hibernateFilter </filter-name>
<url-pattern> /* </url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
<listener>