У меня есть класс AwsSpringWebRuntimeInitializer, предоставленный aws-serverless-java-container -springboot3. Он реализует ApplicationContextInitializer для регистрации определенного компонента (AwsSpringWebCustomRuntimeEventLoop) при запуске приложения. Этот класс регистрируется через файл Spring.factories.
Код: Выделить всё
public class AwsSpringWebRuntimeInitializer implements ApplicationContextInitializer {
private static Log logger = LogFactory.getLog(AwsSpringWebRuntimeInitializer.class);
@Override
public void initialize(GenericApplicationContext context) {
logger.info("AWS Environment: " + System.getenv());
Environment environment = context.getEnvironment();
if (logger.isDebugEnabled()) {
logger.debug("AWS Environment: " + System.getenv());
}
if (context instanceof ServletWebServerApplicationContext && isCustomRuntime(environment)) {
if (context.getBeanFactory().getBeanNamesForType(AwsSpringWebCustomRuntimeEventLoop.class, false, false).length == 0) {
context.registerBean(StringUtils.uncapitalize(AwsSpringWebCustomRuntimeEventLoop.class.getSimpleName()),
SmartLifecycle.class, () -> new AwsSpringWebCustomRuntimeEventLoop((ServletWebServerApplicationContext) context));
}
}
}
private boolean isCustomRuntime(Environment environment) {
String handler = environment.getProperty("_HANDLER");
if (StringUtils.hasText(handler)) {
handler = handler.split(":")[0];
logger.info("AWS Handler: " + handler);
try {
Thread.currentThread().getContextClassLoader().loadClass(handler);
}
catch (Exception e) {
logger.debug("Will execute Lambda in Custom Runtime");
return true;
}
}
return false;
}
}
Код: Выделить всё
public final class AwsSpringWebCustomRuntimeEventLoop implements SmartLifecycle
Есть ли способ заменить AwsSpringWebCustomRuntimeEventLoop на мой собственный или даже заменить AwsSpringWebRuntimeInitializer, чтобы создать необходимый bean-компонент? Я не хотел бы копировать всю библиотеку, поэтому надеюсь, что есть более адекватное решение.
Подробнее здесь: https://stackoverflow.com/questions/784 ... dependency
Мобильная версия