Spring applicationContext. xml and hibernate. cfg. xml settings, hibernate. cfg. xml

Source: Internet
Author: User

Spring applicationContext. xml and hibernate. cfg. xml settings, hibernate. cfg. xml

ApplicationContext. xml configuration

<? 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: context = "http://www.springframework.org/schema/context" xmlns: aop = "http://www.springframework.org/schema/aop" xmlns: tx = "http://www.springframework.org/schema/tx" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans. Xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd> <context: property-placeholder location = "classpath: database. properties"> </context: proper Ty-placeholder> <! -- Use Javabean to read the resource file <bean id = "placeholderConfigurer" class = "org. springframework. beans. factory. config. propertyplaceholderpolicer "> <property name =" location "> <value> classpath: system. properties </value> </property> <property name = "fileEncoding" value = "UTF-8"/> </bean> --> <! -- Specify the packages automatically scanned by IOC --> <context: component-scan base-package = "com. lingdong "> </context: component-scan> <bean id =" messageSource "class =" org. springframework. context. support. resourceBundleMessageSource "> <property name =" basename "value =" messages "/> <property name =" defaultEncoding "value =" UTF-8 "/> <property name =" useCodeAsDefaultMessage "value = "true"/> </bean> <! -- Configure the data source --> <bean id = "dataSource" class = "com. mchange. v2.c3p0. comboPooledDataSource "> <property name =" driverClass "> <value >$ {jdbc. driverClass }</value> </property> <property name = "jdbcUrl"> <value >$ {jdbc. url} </value> </property> <property name = "user"> <value >$ {jdbc. userName} </value> </property> <property name = "password"> <value >$ {jdbc. password} </value> </property> <property name = "initialPoolSize"> <Value >$ {jdbc. initialPoolSize} </value> </property> <property name = "maxPoolSize"> <value >$ {jdbc. maxPoolSize }</value> </property> </bean> <! -- Configure sessionFactory of Hibernate --> <bean id = "sessionFactory" class = "org. springframework. orm. hibernate4.LocalSessionFactoryBean "> <property name =" dataSource "ref =" dataSource "> </property> <property name =" configLocation "> <value >$ {hibernate. cfg. xml} </value> </property> <property name = "mappingLocations"> <value >$ {hibernate. hbm. xml} </value> </property> </bean> <! -- <Bean id = "loggingAspect" class = "com. lingdong. aop. LoggingAspect"/> --> <! -- Enable automatic proxy annotation for Spring Aop --> <! -- <Aop: aspectj-autoproxy proxy-target-class = "true"/> --> <! -- Configure the Aop entry point, section --> <! -- <Aop: config> <aop: pointcut id = "pointcut" expression = "execution (* com. lingdong. aop. *. *(..)) "> </aop: pointcut> <aop: aspect ref =" loggingAspect "> <aop: before method =" before "pointcut-ref =" pointcut "> </aop: before> </aop: aspect> </aop: config> --> <! -- Configure Spring declarative transactions --> <! -- Configure the Transaction Manager --> <bean id = "transactionManager" class = "org. springframework. orm. hibernate4.HibernateTransactionManager "> <property name =" sessionFactory "ref =" sessionFactory "> </property> </bean> <! -- Enable transaction annotation driver and use --> <! -- <Tx: annotation-driven transaction-manager = "transactionManager"> </tx: annotation-driven> --> <! -- Configure transaction properties --> <tx: advice id = "txAdvice" transaction-manager = "transactionManager"> <tx: attributes> <tx: method name = "add *" propagation = "REQUIRED"/> <tx: method name = "select *" read-only = "true"/> <tx: method name = "update *" propagation = "REQUIRED"/> <tx: method name = "delete *" propagation = "REQUIRED"/> <tx: method name = "*"/> </tx: attributes> </tx: advice> <! -- Configure the transaction start point and associate it with the transaction attribute --> <aop: config> <aop: pointcut expression = "execution (* com. lingdong. service. *. *(..)) "id =" pointcut "> </aop: pointcut> <aop: advisor advice-ref =" txAdvice "pointcut-ref =" pointcut "> </aop: advisor> </aop: config> </beans>

 

Hibernate. cfg. xml configuration

<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC        "-//Hibernate/Hibernate Configuration DTD//EN"        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

 

123456789101112 <?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC        "-//Hibernate/Hibernate Configuration DTD//EN"        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">    <session-factory>        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>        <property name="hibernate.hbm2ddl.auto">update</property>        <property name="hibernate.show_sql">true</property>        <property name="hibernate.format_sql">true</property>    </session-factory></hibernate-configuration>

 

This article is from the "Java technology blog" blog, please be sure to keep this source http://lingdong.blog.51cto.com/3572216/1889446

   
0 people This article
Category: spring Festival read (2) publish comments (0) Publish edit publish Delete publish return to blogger homepage publish return to blog homepage previous Git distributed version control tutorial related articles
  • SpringMVC interceptor
  • Spring 3.1 transaction Configuration
  • Spring4.x New Features
  • How to load ApplicationContext. xml files in spring
Job recommendations
  • R & D tools or Environment Development
  • Senior Java Engineer
  • Recruiting a Siebel developer
  • Server Development Engineer
  • Java Development
Post comment back to top

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.