Alibabacloud.com offers a wide variety of articles about spring and hibernate integration, easily find your spring and hibernate integration information here online.
I. ConceptSSH usually refers to the STRUTS2 as the front controller, Spring manages the components of each layer, hibernate is responsible for the persistence layer.SSM refers to the SPRINGMVC as the front controller, Spring manages the components of each layer, and MyBatis is responsible for the persistence layer.Two. Build processCreate Maven Project ... Config
actionsupport to obtain this applicationcontext object, which does not make me feel much benefit. The sample code is as follows:Enumeration E = application. getattributenames ();While (E. hasmoreelements ()){String attributename = (string) E. nextelement ();String objclassname = application. getattribute (attributename). getclass (). getname ();Try{Response. getwriter (). println (attributename + ":" + objclassname + "} Catch (exception ex ){}}Studentmanager = This. getwebapplicationcontext ().
Today's integration of spring and hibernate, with the use of the highest version of the principle, using the Hibernate-validator 6.0.1.Final, Tomcat is the 7.0.56, the following error occurred during startup.After a multi-party search did not search for a more satisfactory answer, and finally found that the
Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.service;import Org.springframework.transaction.annotation.transactional;import Com.iss.dao.userdao;import com.iss.model.user;import Com.iss.service.UserService; @Service ("UserService") @ Transactionalpublic class Userserviceimpl implements UserService {@Autowiredprivate userdaoindex,jspsuccess.jspAfter you have finished writing, right-click on the project to select Run as MVN install,build success and
SSH configuration More, there are many places have been very vague, this time to tidy up ideas.All source files are at the end of the text.XML file: Link: Https://pan.baidu.com/s/1kUHjhAJ Password: b4b3Image Ultra-clear version: Link: https://pan.baidu.com/s/1nvdzMfn Password: z8myXmind Original format: Link: Https://pan.baidu.com/s/1jH7HE1C Password: F4BBMaven + Struts2 + Spring + Hibernate
Hibernate provides its own transaction management implementation. However, when using spring to integrate hibernate, we recommend that you hand over the transaction to spring for programmatic transaction management.
1. User. Java
Package cn.com. Boyang;
Public class user {Private integer ID;Private string name;Private
Integration of the SSH framework (struts-2.5.5+spring-4.3.4+hibernate-5.2.4) 1.jdk-1.8 TOMCAT7 Environment 2. Create a Web Project 3. Guide Package (Struts+spring+hibernate) 4. Create Struts.xml and Spring.xml (applicationcontext.xml) struts.xml header in SRC to add several
Spring learning-Hibernate IntegrationWhat is Spring integrated with Hibernate? 1 ). IOC containers are available to manage SessionFactory2 of Hibernate ). you need to configure the data source to the IOC container so that Hibernate
2 errors1.Org.springframework.beans.factory.NoSuchBeanDefinitionException:No Bean named ' testservice ' is definedThis is becauseStatement: Testservice SE = (testservice) ac.getbean ("Testservice"); Should be:Testservice se = (testservice) ac.getbean ("Testservice"); revised and passed;2.CannotCreateTransactionExceptionAfter found Jdbcurl write wrong, because my MySQL port number is: 3308, and the default is 3306, so I added the port number after the correct:Jdbcurl =jdbc:mysql://localhost:3308/
Go on, I'm going to create another project, Sshtest, and move the Shdemo code in (Shdemo to do something else)
1. Introducing Spring's required jar package
Not only does this need spring's jar package
You also need two data source packages in Hibernate
There is also a Aspectjweaver.jar package, this package in the AOP configuration of the time required, now spring package is not provided, to download the
;Byte [] temp;Try {Temp = S. getbytes (iso-8859-1 ″);Result =New String (temp, "UTF-8 ″);}Return result;}
Finally, set the database:
Take mysql5 as an example. When creating dB and table, set charset to GBK!
Summary:
In short, you must ensure that your character along the way to use the same encoding, preferably UTF-8.
The displayed JSP page must be
In struts2, set
Write a filter to filter characters, also use UTF-8
Database MySQL creates a library encoded with a UTF-8
Note:
When
The core idea is to use spring to manage Hibernate and configure hibernate in spring configuration.
Applicationcontext. xml
Service layer interface
package com.ch.dao;import com.ch.entity.Person;public interface IPersonService {public void save(Person person) ;public void update(Person person);public Person find(Integ
; class= "uuid"/> class>8. Create a person table9. The initialization of the spring container is generally done when the project is started , Web. xml:class>org.springframework.web.context.contextloaderlistenerclass> class>org.springframework.web.servlet.dispatcherservletclass> 10. Create a controller class that handles the person, leaving the process out of the way, regardless of the other.@Controller @requestmapping (Value= "/person")
Struts2 + Spring3 + Hibernate3 Framework Integration1. Use of each frame (development environment construction)* Presentation Layer Frame STRUTS21) Jar Package import: Apps/struts2_blank.war contains struts2 to develop the most basic jar packageStruts2-convention-plugin-2.3.7.jar for struts using annotations (if not developed with annotations, no import required)Struts2-json-plugin-2.3.7.jar for STRUTS2 Integrated AjaxStruts2-spring-plugin-2.3.7.jar f
configuration is configured as a transaction template, and the actual transaction proxy Bean inherits the transaction template. This configuration can reduce some of the configuration code, compared to the previous direct use of Transactionproxyfactorybean transaction proxy configuration, can greatly reduce the amount of code in the configuration file. The configuration of each transaction agent inherits the transaction template, eliminating the need to repeatedly specify the transaction broker
Recently, I have seen a sentence in zhihu. One of the ways to keep learning is that you have seen more cool people who are unwilling to do so.
When Spring and hibernate are integrated, jsp pages are displayed and the display attributes appear:
Org. apache. jasper. JasperException: cocould not initialize proxy-no Session-Class: org. hibernate. proxy. AbstractLazy
Error creating Bean with Name ' TransactionManager ' defined in class path resource [Applicationcontext.xml]: Invocation of Init method failed; Nested exception isOrg.hibernate.service.UnknownUnwrapTypeException:Cannot unwrap to requested type [Javax.sql.DataSource]caused by:org.hibernate.service.UnknownUnwrapTypeException:Cannot unwrap to requested type [Javax.sql.DataSource]The reason for reporting this error is to use the following configurationChange intoThere is sping3.x in the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.