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