一个简单的SPRING配置,一个简单的SERVLET,
配置好了SPRING的service等,然后给SERVLET注入一个bean,发现能注入(TOMCAT启动的时候发现能SET进去),但是调用的一直是NULL,不知道是什么原因,望高手指点.下面是相关代码。SERVLET代码public class Javaservice extends HttpServlet {
private UserService userservice;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,
IOException {
System.out.print("f");
userservice.getaallStudent();(这一句在运行中发现是null)
response.setContentType("text/html");
PrintWriter out = response.getWriter();
}
public UserService getUserservice() {
System.out.println("get------------------------------------");
return userservice;
} public void setUserservice(UserService userservice) {
System.out.println("set------------------------------------");(这一句在TOMCAT启动时发现正常,能注入值)
this.userservice = userservice;
}SPRING_APPLICATION.XML<bean id="userservice" parent="txProxyTemplate">
<property name="target"><ref bean="userserviceImpl"/></property>
<property name="proxyInterfaces">
<value>com.sos.service.UserService</value>
</property>
</bean>
<bean id="userserviceImpl" class="com.sos.service.UserServiceImpl">
<property name="userdao"><ref bean="userdao"/></property>
</bean>
<bean id="userdao" class="com.sos.hibernate.UserDAO">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="Javaservice" class="com.sos.action.Javaservice">
<property name="userservice"><ref bean="userservice"/></property>
</bean>
就是这个问题,不知道为什么用的时候是NULL,同样的方法在SPRINGmvc中就不是NULL
配置好了SPRING的service等,然后给SERVLET注入一个bean,发现能注入(TOMCAT启动的时候发现能SET进去),但是调用的一直是NULL,不知道是什么原因,望高手指点.下面是相关代码。SERVLET代码public class Javaservice extends HttpServlet {
private UserService userservice;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,
IOException {
System.out.print("f");
userservice.getaallStudent();(这一句在运行中发现是null)
response.setContentType("text/html");
PrintWriter out = response.getWriter();
}
public UserService getUserservice() {
System.out.println("get------------------------------------");
return userservice;
} public void setUserservice(UserService userservice) {
System.out.println("set------------------------------------");(这一句在TOMCAT启动时发现正常,能注入值)
this.userservice = userservice;
}SPRING_APPLICATION.XML<bean id="userservice" parent="txProxyTemplate">
<property name="target"><ref bean="userserviceImpl"/></property>
<property name="proxyInterfaces">
<value>com.sos.service.UserService</value>
</property>
</bean>
<bean id="userserviceImpl" class="com.sos.service.UserServiceImpl">
<property name="userdao"><ref bean="userdao"/></property>
</bean>
<bean id="userdao" class="com.sos.hibernate.UserDAO">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="Javaservice" class="com.sos.action.Javaservice">
<property name="userservice"><ref bean="userservice"/></property>
</bean>
就是这个问题,不知道为什么用的时候是NULL,同样的方法在SPRINGmvc中就不是NULL
解决方案 »
- 求助!jsp里查询全部数据?
- 如何解析vt100格式数据?
- 数据库有变化,如何在前台显示出来!
- 求助 jsp远程数据库连接问题
- 在TOMCAT上部署WEB应用程序!!!
- 简单问题,郁闷中!问题解决就结贴,在线等!12点前结帖
- 大位大虾是否能告诉我bean放在哪个地方?
- 我刚学jsp没两天,写了两个jsp程序往sql server2000的数据库里添加中文数据,怎么是乱码啊,(英文好使),100分奉上!!
- 1500分征XML学习心得, 资料集中(参与者均可得分,同开5贴)
- 我用smartupload的上传组件,遇到一点麻烦!
- 急救:页面中的树重新加载,并保留已填写信息
- 这句话放到 out.print中
这边是获取用户信息的代码<b:bean id="userDetailsService" class="com.sos.security.UserDetailsSerivceImpl"></b:bean>public class UserDetailsSerivceImpl extends BaseAction implements org.springframework.security.userdetails.UserDetailsService{
private UserService userService;
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException,
DataAccessException {
// TODO Auto-generated method stub
// HttpServletRequest request;
// ServletContext servletContext = request.getSession().getServletContext();
// ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
// UserService userservice =(UserService) ctx.getBean("userservice");
com.sos.hibernate.User userinfo=(com.sos.hibernate.User) userService.getStudentInfo(username);//这边需要一个SERVICE ,但是实在是不知道怎么注入.//
if(userinfo==null){
throw new UsernameNotFoundException(username + " 不存在");
}
List <GrantedAuthority> authsList=new ArrayList<GrantedAuthority>();
for(Roles role : userinfo.getRoles()){
authsList.add(new GrantedAuthorityImpl(role.getName()));
}
User userdetail = new User(userinfo.getUsername(), userinfo.getPassword(), true,
true, true, true, authsList.toArray(new GrantedAuthority[authsList.size()]));
return userdetail;
}
}