Spring注入后Action接收不到!!
我的Spring在服务器启动时被注入,但是在Action中,当Action被访问,那么注入的属性都变为null~求解啊!!!
2011-10-11 17:57:53 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
ServiceDAO真心注入了 sun.common.ServiceDAO@71cb25
com.news.app.user.UserService@c510e3
2011-10-11 17:57:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2011-10-11 17:57:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory Test
2011-10-11 17:57:56 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-80
2011-10-11 17:57:56 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2011-10-11 17:57:56 org.apache.catalina.startup.Catalina start
信息: Server startup in 6294 ms
null
com.sun.dao.FirstTypeDAOImpl@993730
Action代码
package com.news.app.user;import java.sql.SQLException;import com.sun.dao.FirstTypeDAOImpl;import sun.common.SunActionSupport;public class UserAction extends SunActionSupport{ private UserService userService; private FirstTypeDAOImpl firsttypeDAO; public FirstTypeDAOImpl getFirsttypeDAO() { return firsttypeDAO; } public void setFirsttypeDAO(FirstTypeDAOImpl firsttypeDAO) { this.firsttypeDAO = firsttypeDAO; } public UserService getUserService() { return userService; } public void setUserService(UserService userService) { this.userService = userService; } @Override public String add() throws Exception { // TODO Auto-generated method stub return null; } @Override public String addView() throws Exception { // TODO Auto-generated method stub return null; } @Override public String delete() throws Exception { // TODO Auto-generated method stub return null; } @Override public String edit() throws Exception { // TODO Auto-generated method stub return null; } @Override public String editView() throws Exception { // TODO Auto-generated method stub return null; } @Override public String list() throws Exception { // TODO Auto-generated method stub return null; } //登录LoginAction public String Login() throws SQLException{ System.out.println(userService+"\n"+firsttypeDAO);// if(condition=="login"){// System.out.println(user.getUser_name());//// getSession().put("user_name", user.getUser_name());//// getSession().put("password", user.getPassword());//// getSession().put("user_lvl", user.getUser_lvl());// System.out.println("登录成功");// return LOGIN;// }// else{// System.out.println("登录失败");// return ERROR;// } return "login"; } @Override public String search() throws Exception { // TODO Auto-generated method stub return null; }}
package com.news.app.user;import java.sql.SQLException;import sun.common.ServiceDAO;import sun.common.newsService;import com.sun.dao.UserDAO;import com.sun.vo.UserExample;public class UserService implements newsService{ private ServiceDAO userService; private String password; private int user_lvl; private String user_name; public int getUser_lvl() { return user_lvl; } public void setUser_lvl(int userLvl) { user_lvl = userLvl; } public String getPassword() { return password; } public String getUser_name() { return user_name; } public void setPassword(String password) { this.password = password; } public void setUser_name(String userName) { user_name = userName; } public ServiceDAO getUserService() { return userService; } public void setUserService(ServiceDAO userService) { System.out.println(this); this.userService = userService; } public String addService() throws SQLException { // TODO Auto-generated method stub UserExample example = new UserExample(); com.sun.vo.UserExample.Criteria criteria = example.createCriteria(); criteria.andPasswordEqualTo(password).andUserNameEqualTo(user_name); //判断是否有此人 if(!userService.getUserDAO().selectByExample(example).isEmpty()){ //用户信息及等级存入session user_lvl=userService.getUserDAO().selectByExample(example).get(0).getUserLvl(); return "login"; } return "error"; } public String addViewService() throws SQLException { // TODO Auto-generated method stub return null; } public String deleteService() throws SQLException { // TODO Auto-generated method stub return null; } public String editService() throws SQLException { // TODO Auto-generated method stub return null; } public String editViewService() throws SQLException { // TODO Auto-generated method stub return null; } public String listService() throws SQLException { // TODO Auto-generated method stub return null; } public String searchService() throws SQLException { // TODO Auto-generated method stub return null; } }
package sun.common;import com.sun.dao.FileDAOImpl;import com.sun.dao.FirstTypeDAOImpl;import com.sun.dao.LinkDAOImpl;import com.sun.dao.NewsDAOImpl;import com.sun.dao.RoleDAOImpl;import com.sun.dao.SecondTypeDAOImpl;import com.sun.dao.TeacherDAOImpl;import com.sun.dao.UserDAOImpl;public class ServiceDAO { private FirstTypeDAOImpl firsttypeDAO; private SecondTypeDAOImpl secondtypeDAO; private NewsDAOImpl newsDAO; private TeacherDAOImpl teacherDAO; private UserDAOImpl userDAO; private LinkDAOImpl linkDAO; private RoleDAOImpl roleDAO; private FileDAOImpl fileDAO; public FirstTypeDAOImpl getFirsttypeDAO() { return firsttypeDAO; } public void setFirsttypeDAO(FirstTypeDAOImpl firsttypeDAO) { this.firsttypeDAO = firsttypeDAO; } public SecondTypeDAOImpl getSecondtypeDAO() { return secondtypeDAO; } public void setSecondtypeDAO(SecondTypeDAOImpl secondtypeDAO) { this.secondtypeDAO = secondtypeDAO; } public NewsDAOImpl getNewsDAO() { return newsDAO; } public void setNewsDAO(NewsDAOImpl newsDAO) { this.newsDAO = newsDAO; } public TeacherDAOImpl getTeacherDAO() { return teacherDAO; } public void setTeacherDAO(TeacherDAOImpl teacherDAO) { this.teacherDAO = teacherDAO; } public UserDAOImpl getUserDAO() { return userDAO; } public void setUserDAO(UserDAOImpl userDAO) { System.out.println("ServiceDAO真心注入了 "+this); this.userDAO = userDAO; } public LinkDAOImpl getLinkDAO() { return linkDAO; } public void setLinkDAO(LinkDAOImpl linkDAO) { this.linkDAO = linkDAO; } public RoleDAOImpl getRoleDAO() { return roleDAO; } public void setRoleDAO(RoleDAOImpl roleDAO) { this.roleDAO = roleDAO; } public FileDAOImpl getFileDAO() { return fileDAO; } public void setFileDAO(FileDAOImpl fileDAO) { this.fileDAO = fileDAO; } // public String toString(){// return getUserDAO()+""+getFirsttypeDAO()+getNewsDAO()+getTeacherDAO();// } }