spring4+hibernate4+struts2注解,class找不到bean
程序员文章站
2022-06-05 14:17:07
...
最近想整合S2SH,采用的是spring4+hibernate4+struts2+maven+MySQL+jdk1.8+tomcat7.
整个项目采用注解实现:spring、hibernate都采用注解实现.
struts.xml:
<constant name="struts.objectFactory" value="spring"/> <constant name="struts.devMode" value="true"/> <constant name="struts.configuration.xml.reload" value="true"/> <constant name="struts.serve.static.browserCache" value="false"/> <constant name="struts.i18n.encoding" value="UTF-8"/> <constant name="struts.i18n.reload" value="true"/> <constant name="struts.multipart.maxSize" value="104857600"/> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <package name="common" extends="struts-default"></package> <package name="login" namespace="/login" extends="common"> <action name="login" class="userLogin"> <result name="loginFail">fail.jsp</result> <result name="success">index.jsp</result> </action> </package>
spring.xml:
<context:annotation-config/> <context:component-scan base-package="com.value.yun.modules" />
controller中的java代码:
package com.value.yun.modules.controller;
import com.opensymphony.xwork2.ActionSupport;
import com.value.yun.common.base.Encryption;
import com.value.yun.modules.entity.User;
import com.value.yun.modules.service.UserService;
import com.value.yun.utils.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
/**
* Created by 丽 on 2015/4/16.
*/
@Controller
public class LoginController extends ActionSupport{
public LoginController(){
System.out.println("============login controller constructor==========================");
}
private User user;
@Autowired
private UserService userService;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@RequestMapping(value = "userLogin")
public String login(){
HttpServletRequest request = ServletActionContext.getRequest();
if (user==null){
request.setAttribute("loginFail","对象为空");
return "loginFail";
}
if(StringUtils.isBlank(user.getLoginName())){
request.setAttribute("loginFail","登录账号为空");
return "loginFail";
}
if (StringUtils.isBlank(user.getPassword())){
request.setAttribute("loginFail","登录密码为空");
return "loginFail";
}
request.setAttribute("loginName",user.getLoginName());
request.setAttribute("password", Encryption.encrytMD532(user.getPassword()));
return "success";
}
}
上面无参构造方法是有执行的,在启动tomcat的时候执行的。
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta name="decorator" content="default"/>
<title>欢迎来到登录界面</title>
</head>
<body>
<h2>Hello World!</h2>
<form action="${baseUrl}/login/login" method="post" class="loginForm">
<table>
<tr>
<th>账号:</th>
<td><input type="text" name="user.loginName"></td>
</tr>
<tr>
<th>密码:</th>
<td><input type="password" name="user.password"></td>
</tr>
<tr>
<td><button type="submit">登录</button></td>
<td><button type="reset">重置</button></td>
</tr>
</table>
</form>
${loginName}<br>
${password}
</body>
</html>
在点击登陆的时候,他就提示<action name="login" class="userLogin">这一行出错。
具体信息如下:
Unable to instantiate Action, userLogin, defined for 'login' in namespace '/login'userLogin - action - file:/D:/yun_systems/hua_yu/source/EASMS/target/EASMS/WEB-INF/classes/struts/login.xml:8:48
请问,有没有人知道这是怎么回事啊?
上一篇: 宝宝喝奶四个注意事项 断奶不等于不喝奶
下一篇: 宝宝养胃掌握八秘诀 可彻底远离胃病