Spring-config.xml database operation bean Configuration

Source: Internet
Author: User

 

<? XML version = "1.0" encoding = "UTF-8" ?>
< Beans
Xmlns = "Http://www.springframework.org/schema/beans"
Xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" >
< Bean ID = "Database"
Class = "Org. Apache. commons. DBCP. basicdatasource" >
< Property Name = "Driverclassname"
Value = "Com. MySQL. JDBC. Driver" >
</ Property >
< Property Name = "Url"
Value = "JDBC: mysql: // localhost: 3306/test? Characterencoding = GBK" >
</ Property >
< Property Name = "Username" Value = "Root" > </ Property >
< Property Name = "Password" Value = "Sa" > </ Property >
</ Bean >
< Bean ID = "Sessionfactory"
Class = "Org. springframework. Orm. hibernate3.localsessionfactorybean" >
< Property Name = "Datasource" >
< Ref Bean = "Database"   />
</ Property >
< Property Name = "Hibernateproperties" >
< Props >
< Prop Key = "Hibernate. dialect" >
Org. hibernate. dialect. mysqldialect
</ Prop >
< Prop Key = "Hibernate. show_ SQL" >
True
</ Prop >
</ Props >
</ Property >
< Property Name = "Mappingresources" >
< List >
< Value > COM/model/login. HBM. xml </ Value >
< Value > COM/model/U. HBM. xml </ Value >
</ List >
</ Property >
</ Bean >
< Bean ID = "Userdao" Class = "Com. Dao. userdao" >
< Property Name = "Sessionfactory" >
< Ref Bean = "Sessionfactory" > </ Ref >
</ Property >
</ Bean >
< Bean ID = "Userbo" Class = "Com. Bo. userbo" >
< Property Name = "Userdao" >
< Ref Bean = "Userdao" > </ Ref >
</ Property >
</ Bean >
< Bean Name = "/Register" Class = "Com. Action. registeraction" >
< Property Name = "Userbo" >
< Ref Bean = "Userbo" > </ Ref >
</ Property >
</ Bean >
</ Beans >

Database Operations

Public static void main (string [] ARGs) {
applicationcontext context = new filesystemxmlapplicationcontext ("webroot/WEB-INF/spring-config.xml ");
iuserbo userbo = (iuserbo) context. getbean ("userbo");
login Login = New Login ();
login. setusername ("Zhong");
login. setpassword ("5");
userbo. saveuserinfo (LOGIN);
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.