spring 配置、注解理解



   
       
   
   
       
       
   


       类2 p = (类2) context.getBean("p");
        System.out.println(p.getName());
        System.out.println(p.get类1().getName());
  
     
        
    
    
        
   
    

@Autowired
private 类1  category;

@Autowired
public void setCategory(Category category) 

@Resource(name="c")
private 类1 category;
xml只有:
 

为Product类加上@Component注解,即表明此类是bean
@Component("p")
public class Product {



声明业务对象

声明日志切面
expression=
"execution(* com.service.ProductService.(..)) "/>
指定右边的核心业务功能



指定左边的辅助功能
然后通过aop:config把业务对象与辅助功能编织在一起。
execution(
com.service.ProductService.(..))
这表示对满足如下条件的方法调用,进行切面操作: * 返回任意类型
com.service.ProductService.

包名以 com.service.ProductService 开头的类的任意方法
(..) 参数是任意数量和类型

@Aspect 注解表示这是一个切面
@Component 表示这是一个bean,由Spring进行管理
@Around(value = "execution(* com.service.ProductService.*(..))") 表示对com.service.ProductService 这个类中的所有方法进行切面操作
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


你可能感兴趣的:(spring 配置、注解理解)