SSH integration Fourth spring IOC and AOP

Source: Internet
Author: User

This article is primarily about testing IOC and AOP applications after integrating Hibernate.

1. Engineering Catalogue (SRC)

2, IoC1), a service test class
1 /*2 * Join Spring container3  */4 PrivateApplicationContext ApplicationContext =5         6         NewClasspathxmlapplicationcontext ("classpath:spring/applicationcontext.xml");7  public Static voidmain (string[] Args) {8     Newuserservicetest (). testgetuserandrole ();9 }Ten  one  public voidtest1 () { aUserService userservice= (userservice) Applicationcontext.getbean ("userservice"); -User user = Userservice.getbyid ("u1"); -System.out.println (user.getid () + "---" +user.getusername ()); the}
userservicetest

2), Userserviceimpl

From user user = Userservice.getbyid ("u1"), call Userserviceimpl. (omit the Paste interface below).

And look at Userserviceimpl.

so, What should spring containers be set up for?

others, in the same vein.

3), Component Scan

For each bean configuration, it may be a bit cumbersome to use component scan

For example, Roleserviceimpl

XML file, It is

3. AOP

Here is the application of transaction Management. The settings in spring are as Follows.

<!--Transaction Management - <BeanID= "transactionmanager"class= "org.springframework.orm.hibernate4.HibernateTransactionManager">    < propertyname= "sessionfactory"ref= "sessionfactory" /></Bean><Aop:config>    <Aop:advisorAdvice-ref= "txadvice"pointcut= "execution (* com.xzw.ssh.service.impl.*.* (..))" /></Aop:config><Tx:adviceID= "txadvice"Transaction-manager= "transactionmanager">    <tx:attributes>        <Tx:methodname= "get*"read-only= "true"Propagation= "REQUIRED"/><!--before it was Not_support . -        <Tx:methodname= "find*"read-only= "true"Propagation= "REQUIRED"/><!--before it was Not_support . -        <Tx:methodname= "save*"Propagation= "REQUIRED"/>        <Tx:methodname= "update*"Propagation= "REQUIRED"/>        <Tx:methodname= "remove*"Propagation= "REQUIRED"/>        <Tx:methodname= "add*"Propagation= "REQUIRED"/>        <!--the default other methods are required -        <Tx:methodname="*"/>    </tx:attributes></Tx:advice>
transactions in the Springxml

Attention

In the use of aop, the previously imported package is not enough, there will be "no class found" prompt, keywords, org/aopalliance/intercept/methodinterceptor and org/aspectj/weaver, Correspondence to join Aopalliance-1.0.jar and Aspectjweaver.jar

At this point, the integration of spring and hibernate is basically complete.

SSH integration Fourth spring IOC and AOP

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.