发表于: 2018-02-05 23:32:38
1 803
搭SSM框架:
报错:java.lang.IllegalStateException: Failed to load ApplicationContext
Causedby: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController' defined infile[E:\project\ssm\target\classes\com\alibaba\controller\UserController.class]:BeanPostProcessor before instantiation of bean failed; nested exception isorg.springframework.beans.factory.BeanCreationException: Error creating beanwith name'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0':Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError:org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
报错:Error creating bean with name Initialization of bean failed
在POM.xml里面加入aspectjweaver.jar包就行了
<dependency>
<groupId> org.aspectj</groupId >
<artifactId> aspectjweaver</artifactId >
<version> 1.8.7</version >
</dependency>
继续报错:Could not autowire field: private com.alibaba.service.UserService com.alibaba.controller.UserController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.alibaba.mapper.UserMapper com.alibaba.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.alibaba.mapper.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
今天根据一个新的教程,把student给替换了
首先是studentjava类
public class Student {
private int id;
private String name;
private int qq;
private String major;
public Student() {
super();
}
public Student(int id,String name,int qq,String major) {
super();
this.id = id;
this.name = name;
this.qq = qq;
this.major = major;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getQq() {
return qq;
}
public void setQq(int qq) {
this.qq = qq;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
然后是studentService
public interface StudentService {
void saveStudent(Student student);
boolean deleteStudent(int id);
boolean updateStudent(Student student);
Student findStudentById(int id);
List<Student> findAll();
}
StudentServiceImpl
@Service
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
@Override
public void saveStudent(Student student) {
studentMapper.saveStudent(student);
}
@Override
public boolean updateStudent(Student student) {
return studentMapper.updateStudent(student);
}
@Override
public boolean deleteStudent(int id) {
return studentMapper.deleteStudent(id);
}
@Override
public Student findStudentById(int id) {
Student student = studentMapper.findStudentById(id);
return student;
}
@Override
public List<Student> findAll(){
List<Student> allStudent = studentMapper.findAll();
return allStudent;
}
}
StudentController里面
@Controller
@RequestMapping("/student")
public class StudentController {
@Resource
private StudentService studentService;
@RequestMapping(value = "/student/u/{id}",method = RequestMethod.DELETE)
public String deleteStudent(@PathVariable int id){
studentService.deleteStudent(id);
//传值必须要有model.addAttribute方法
return "redirect:/student/list";
}
@RequestMapping(value = "/student/list",method = RequestMethod.GET)
public String list(Model model){
List<Student> students=studentService.findAll();
model.addAttribute("studentList", students);
return "listJsp";
}
}
运行,成功
后来做了个进入管理的页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
pageContext.setAttribute("path", request.getContextPath());
%>
<!DOCTYPE html >
<html>
<head>
<title>首页</title>
<style type="text/css">
a {
text-decoration: none;
color: #fff;
font-size: 14px;
}
h3 {
width: 180px;
height: 38px;
margin: 100px auto;
text-align: center;
line-height: 38px;
background: #5BC0DE;
border-radius: 4px;
}
</style>
</head>
<body>
<h3>
<a href="${pageContext.request.contextPath}/student/student/list">进入用户管理页</a>
</h3>
</body>
</html>
运行tomcat,显示如图:
点击进入:
明天的计划:继续在网页上增改
遇到的问题:还是没能实现在网页上增改的目标
今天的收获:新搭了个框架,并且运行成功了,多了个页面
java任务二开始时间:2018.01.25
预计demo时间:2018.02.12
可能有延期风险,原因是:基础比较差,
禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html
评论