import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.redis.core.StringRedisTemplate; /** Real component scan, with no Boot auto-config or external Redis connection. */ public class PublisherBeanScanRegression { static class Consumers { @Autowired com.zksy.base.event.DeviceStatusChangePublisher management; @Autowired com.zksy.api.event.DeviceStatusChangePublisher collection; } public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { context.getDefaultListableBeanFactory().setAllowBeanDefinitionOverriding(false); context.registerBean(ObjectMapper.class, () -> new ObjectMapper()); context.registerBean(StringRedisTemplate.class, () -> new StringRedisTemplate() { @Override public void afterPropertiesSet() { /* no external connection */ } }); context.registerBean(Consumers.class); context.scan("com.zksy.base.event", "com.zksy.api.event"); context.refresh(); Consumers consumers = context.getBean(Consumers.class); if (consumers.management == null || consumers.collection == null) { throw new AssertionError("Both publisher types must remain injectable"); } if (context.getBeanNamesForType(com.zksy.base.event.DeviceStatusChangePublisher.class).length != 1 || context.getBeanNamesForType(com.zksy.api.event.DeviceStatusChangePublisher.class).length != 1) { throw new AssertionError("Each publisher type must have exactly one bean"); } System.out.println("PASS: both publishers scan and inject without bean overriding or external services"); } } }