I have a class:
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class WebSocketRegistrar extends AbstractWebSocketHandler{
private final ApplicationContext context;
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
// problem here.
context.getBean(WebSocketConsumer.class, session);
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
}
}
and it attempts to create a prototype bean where 1 of the parameters is a runtime argument and the rest I want injected. I need it to take the EventBus and a function. Both are available in the context and I can work past this problem. I am trying to understand how I can do partial constructor autowiring on a prototype
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@NoArgsConstructor
public class WebSocketConsumer implements Consumer<Identifiable<?>> {
private WebSocketSession session;
private Function<Identifiable<?>, String> jsonApi;
@Autowired
public WebSocketConsumer(WebSocketSession session, EventBus bus, BiFunction<Identifiable<?>, String, String> toJsonApi) {
this.session = session;
this.jsonApi = identifiable -> toJsonApi.apply(identifiable,session.getHandshakeHeaders().get("Host").get(0));
bus.on(R(session.getUri().getPath() + "/?.*"),this::accept);
}
@Override
public void accept(Identifiable<?> update) {
}
}