1-spring managed bean in two ways
Principle: Spring to manage objects through the large collection Map, default conditions are singletons
Format: Map <K, V> key: bean of ID / @Bean annotation method name
value: After the object is instantiated
Requirements: The name of the container object key, must be different.
-1- by label management bean
<bean id="a" class="com.tedu.controller.A"/>
-2- by bean annotation management
@Bean public A a(){ return new A(); }
The effect of 2-AOP: In order to expand the method to achieve a decoupled service code
Section structure elements: section = + entry point notification
Transaction control to solve the problem in the form of AOP:
public void saveUser (the User User) { userMapper.insert (User); } public void the updateUser (the User User) { userMapper.update (User); }
@Component
@Aspect
public class TxAspect {
/ * transaction / cache / exception processing may around advice * / / * if desired to control the target process execution, around advice * / @Around ( "execution (com.jt.service .. * * (..))") public Object around (ProceedingJoinPoint Joinpoint) { {the try tx.begin (); joinPoint.proceed (); // make certain method performed tx.commit (); } the catch () { Tx.rollback (); } }
Pointcut expression:
-1-Bean according to a Bean (class) shRNA
-2-within (package name. Class name) as Class interception
-3-execution (the package name return type. Class name. Method name (parameter list))
-4- @ annotaion (package name. Notes name)