NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
**1.注解配置类** ~~~ package com.nobb; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; //声明是spring容器的配置类 @Configuration //扫描基础包及子包 @ComponentScan("com.nobb") //开启自动扫描aop注解 @EnableAspectJAutoProxy public class ApplicationContextConfiguration { } ~~~ **2.测试代码** ~~~ import com.nobb.ApplicationContextConfiguration; import com.nobb.service.UserService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ApplicationContextConfiguration.class) public class AopTest1 { @Resource(name="userService") private UserService userService; @Test public void fun1(){ userService.save(); } } ~~~