spring.aop.proxy-target-class=false в
application.properties не помогает мне заставить Spring Boot2 использовать JDK Proxy.
Аспект
private Logger logger = LoggerFactory.getLogger(this.getClass());
private final String POINT_CUT = "execution(* weatherReport.entity.*.*(..)))";
@Pointcut(POINT_CUT)
private void pointcut() {}
@Before(value = "pointcut()")
public void before(JoinPoint pjp) {
logger.info(" Check for user access ");
logger.info(" Allowed execution for {}", pjp);
}
Целевой компонент:
@Component
public class Hello {
public String name = "default";
public String helloStr = "Guys";
public void saySomething() {
System.out.println(this.name+":"+this.helloStr);
}
}
Контроллер:
@Autowired
private WeatherQueryService weatherservice;
@Autowired
private Hello hello;
@RequestMapping(value = "/hello")
public String sayHello() {
System.out.println(weatherservice);
System.out.println(hello.getClass());
hello.saySomething();
System.out.println(hello.getClass());
System.out.println(weatherservice.getClass());
return "hello world";
}
result: class weatherReport.entity.Hello$$EnhancerBySpringCGLIB$$b853a6c3
приложение.свойства
spring.aop.auto=true
spring.aop.proxy-target-class=false




Хорошо, я пропустил важную теорию о JDK Proxy, целевой класс должен реализовывать интерфейс, тогда мы можем использовать JDK Proxy. В моем коде WeatherService реализует интерфейс, и когда я устанавливаю для spring.aop.proxy-target-class значение false, Spring Boot 2 использует JDK Proxy:
класс com.sun.proxy.$Proxy62
но когда я устанавливаю для spring.aop.proxy-target-class значение true, Spring Boot2 использует прокси-сервер cglib по умолчанию: класс WeatherReport.service.impl.WeatherQueryServiceImpl$$EnhancerBySpringCGLIB$$40d58c6