There are some class in jar (external library), that uses Spring internally. So library class has structure like a:
Based on @Juan's answer, created a helper to wrap a bean not to be autowired:
public static FactoryBean preventAutowire(T bean) {
return new FactoryBean() {
public T getObject() throws Exception {
return bean;
}
public Class> getObjectType() {
return bean.getClass();
}
public boolean isSingleton() {
return true;
}
};
}
...
@Bean
static FactoryBean myBean() {
return preventAutowire(new MyBean());
}