💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**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(); } } ~~~