麻利麻利吼 2021-06-13 12:00 采纳率: 0%
浏览 27

Java报错 'sessionFactory' is required

我搭建Java搭建SSH框架的时候报错总是报错'sessionFactory' or 'hibernateTemplate' is required,但是在applicationContext.xml中dao层添加了sessionFactory的注入了;实在不知道哪里错了,有人可以看一下吗?

applicationContext.xml:

package org.action;

import org.model.Student;
import org.service.StudentService;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.opensymphony.xwork2.ActionContext;

public class StudentAction extends HibernateDaoSupport{
	private StudentService studentService;
	private Student student;

	public void setStudent(Student student) {
		this.student = student;
	}
	//set注入
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	
	//添加学生
	public String addStudent() throws Exception{
		if(student.getSId()==null||"".equals(student.getSId())){
			ActionContext.getContext().put("error", "输入账号有误");
			return "error";
		}
		student.setPwd("123456");
		
		//查找学号
		//不存在
		if( null != studentService.findById(student.getSId())){
			studentService.save(student);
			System.out.println("添加成功!");
			return "addsuccess";
		}
		//存在
		else{
			ActionContext.getContext().put("error", "用户已存在!");
		}
		return "error";
	}
}

StudentAction.java:

 

package org.action;

import org.model.Student;
import org.service.StudentService;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.opensymphony.xwork2.ActionContext;

public class StudentAction extends HibernateDaoSupport{
	private StudentService studentService;
	private Student student;

	public void setStudent(Student student) {
		this.student = student;
	}
	//set注入
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	
	//添加学生
	public String addStudent() throws Exception{
		if(student.getSId()==null||"".equals(student.getSId())){
			ActionContext.getContext().put("error", "输入账号有误");
			return "error";
		}
		student.setPwd("123456");
		
		//查找学号
		//不存在
		if( null != studentService.findById(student.getSId())){
			studentService.save(student);
			System.out.println("添加成功!");
			return "addsuccess";
		}
		//存在
		else{
			ActionContext.getContext().put("error", "用户已存在!");
		}
		return "error";
	}
}

提交表单页面:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!doctype html>
<html>
<head>
    <title>添加学生信息</title>
</head>
<body>
	<h3>
		请填写学生信息
	</h3>
	<hr width="700" align="left">
		<s:form action="addStudentAction" method="get" >
			<table>
				<tr>
					<td>
						<s:textfield name="student.SId" label="学号" value=""></s:textfield>
					</td>
				</tr>
				<tr>
					<td>
						<s:textfield name="student.SName" label="姓名" value=""></s:textfield>
					</td>
				</tr>
				<tr>
					<td>
						<s:radio name="student.sex" value="1" list="#{1:'男',0:'女'}" label="性别" />
					</td>
				</tr>
				<tr>
					<td>
						<s:textfield name="student.age" label="年龄" value=""></s:textfield>
					</td>
				</tr>
				<tr>
					<td>
						<s:textfield name="student.SSubject" label="专业" value=""></s:textfield>
					</td>
				</tr>
				<tr>
					<td>
						<s:textfield name="student.tel" label="电话" value=""></s:textfield>
					</td>
				
				</tr>
				<tr>
					<td>
						<s:textfield name="student.adddr" label="地址" value=""></s:textfield>
					</td>
				</tr>
				
			</table>
			<p>
				<input type="submit" value="添加" />
				<input type="reset" value="重置" />
		</s:form>
</body>
</html>

structs.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<package name="default" extends="struts-default">		
		<!-- 登录 -->
		<action name="LoginAction" class="loginaction">
			<result name="admin">admin/admin.jsp</result>
			<result name="student">student/student.jsp</result>
			<result name="teacher">teacher/teacher.jsp</result>
			<result name="error">error.jsp</result>
		</action>
		
		<!-- 添加学生 -->
		<action name="addStudentAction" class="studentaction" method = "addStudent">
		</action>
	</package>
</struts>    

 

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-06-13 12:07
    关注

    'sessionFactory' or 'hibernateTemplate没注入成功吧

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器