Please ignore this issue when it's an expected behavior. (I asked, don't worry.)
I've just found that a event listener received on different objects depending on the style(?).
Case 1
public abstract class _ApiController {
@EventListener
void onApplicationEvent(final ReactiveWebServerInitializedEvent event) {
// `this`: SomeApiController$$SPRINGCGLIB@... instance.
webServer = event.getWebServer();
}
WebServer webServer;
}
@Validated // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@RestController
class SomeApiController
extends _ApiController {
@GetMapping(path = "/")
Mono<Void> read(final ServerHttpResponse response) {
// `this` is an instance of SomeApiController$$SPRINGCGLIB@...
// super.webServer is null
}
}
Case 2
public abstract class _ApiController
implements ApplicationListener<ReactiveWebServerInitializedEvent> {
@Override
public void onApplicationEvent(final ReactiveWebServerInitializedEvent event) {
// `this` is not a proxy anymore
webServer = event.getWebServer();
}
WebServer webServer;
}
@Validated // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@RestController
class SomeApiController
extends _ApiController {
@GetMapping(path = "/")
Mono<Void> read(final ServerHttpResponse response) {
// `this` is an instance of SomeApiController@...
// super.webServer is not null
}
}
Is this an expected behavior?
Comment From: mdeinum
This is expected behavior due to how proxies work. The main problem here being your method isn't public (or protected) and that leads the read being invoked on the proxy instead of being passed on to the wrapped object. The wrapped object does have the fields set, the proxy doesn't.