Я пытаюсь реализовать страницу регистрации с помощью Spring MVC, интегрированной с Hibernate с использованием XML.
Application Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
xmlns:tx="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"></property>
<property name="username" value="hr"></property>
<property name="password" value="umashetti123"></property>
</bean>
<bean id="mysessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>Login_Detailshbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="checkWriteOperation" >false</prop>
</props>
</property>
</bean>
<bean id="template" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="mysessionFactory"></property>
<property name="checkWriteOperations" value="false"></property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="mysessionFactory" />
</bean>
<bean id="d" class="com.uday.Login_DetailsDao">
<property name="template" ref="template"></property>
</bean>
</beans>
Класс контроллера
package com.uday;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class ControllerSignUp_Login {
public ControllerSignUp_Login() {
// TODO Auto-generated constructor stub
}
@RequestMapping("/hello")
public String diaplay(@RequestParam("name") String name, @RequestParam("pass") String pass,Model m) {
Login_DetailsDao dao = (Login_DetailsDao) getBean();
if(dao.isLogoinSuccessfull(name , pass)) {
m.addAttribute("message", "Hello"+name);
return "Success";
}
else {
m.addAttribute("message", "You have Entered Wrong pin");
return "Failure";
}
}
@RequestMapping("/SignUp")
public String redirect() {
System.out.println("ControllerSignUp_Login.display()");
return "signup";
}
@RequestMapping("/login")
public String display() {
System.out.println("ControllerSignUp_Login.display()");
return "login";
}
@RequestMapping("/updateDetails")
@Transactional
public String display(HttpServletRequest req , Model M) {
String firstName=req.getParameter("firstName");
String lastName=req.getParameter("lastName");
String mobileNo=req.getParameter("mobileNo");
String address=req.getParameter("address");
String city=req.getParameter("city");
String password=req.getParameter("password");
Login_DetailsDao dao = (Login_DetailsDao) getBean();
if(checkLength(firstName) && checkLength(lastName) && checkLength(mobileNo) && checkLength(address) && checkLength(city) && checkLength(password)) {
Login_Details ld = new Login_Details();
ld.setFirstName(firstName);
ld.setLastName(lastName);
ld.setCity(city);
ld.setAddress(address);
ld.setMobileNo(mobileNo);
ld.setPassword(password);
dao.saveEmployee(ld);
M.addAttribute("message", "SignUp Successfull !! Thank You");
M.addAttribute("displayLogin", true);
return "Success";
}
else {
M.addAttribute("message","SignUp Failed !! All details are mandatory.");
return "signup";
}
}
public boolean checkLength(String s) {
if(s != null && s.length() > 0) {
return true;
}
return false;
}
public Object getBean() {
ApplicationContext appcontext = new ClassPathXmlApplicationContext("Applicationcontext.xml");
Login_DetailsDao lDDao =(Login_DetailsDao)appcontext.getBean("d");
return lDDao;
}
}
DAO class
package com.uday;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.transaction.annotation.Transactional;
public class Login_DetailsDao {
HibernateTemplate template;
HibernateTransactionManager hbt;
public HibernateTransactionManager getHbt() {
return hbt;
}
public void setHbt(HibernateTransactionManager hbt) {
this.hbt = hbt;
}
public Login_DetailsDao() {
// TODO Auto-generated constructor stub
}
@Transactional
public void saveEmployee(Login_Details e){
System.out.println("Login_DetailsDao.saveEmployee()"+e.getMobileNo());
SessionFactory sf = hbt.getSessionFactory();
Session session =sf.getCurrentSession();
Transaction t =session.beginTransaction();
session.persist(e);
t.commit();
session.close();
}
public void setTemplate(HibernateTemplate template) {
this.template = template;
}
public List<Login_Details> getEmployees(){
List<Login_Details> list=new ArrayList<Login_Details>();
list=template.loadAll(Login_Details.class);
return list;
}
}
Я могу получить данные login_details, но не могу вставить запись.
получить ниже исключения
org.xml.sax.SAXParseException;номер строки: 51;номер столбца: 29;cvc-complex-type.2.4.c: Соответствующий шаблон является строгим, но не найдено ни одного объявления для элемента 'tx: annotation-driven'.
Может ли кто-нибудь предложить решение этой проблемы?