测试代码:
@RestController
@Scope("prototype")
public class TestController {
private static TestService testService;
//这个方法不要为static
@Autowired
private void setTestService(TestService testService){
System.out.println("注入了-----------");
TestController.testService = testService;
}
@RequestMapping("/r")
public Object test2(){
testService.doSth();
return null;
}}
运行结果:
不管这个TestService是不是静态的都会多次注入。