应用程序启动时如何使用spring IOC创建对象的多个实例

时间:2018-10-26 13:16:10

标签: java spring spring-mvc spring-boot

我下面是Listener类。我的应用程序是spring boot应用程序。我在配置类中实例化它。但是我希望当应用程序启动时&当应用程序停止时必须创建100个实例,所有实例对象必须关闭。就像我们在连接池中所做的一样。有人可以建议实现此目标的最佳方法吗?下面是我的侦听器类以及在我的配置类中用于实例化侦听器类的代码。

@EnableRabbit
public class SubscriberGeneralQueue1 {

     /*@Autowired
        @Qualifier("asyncGeneralRabbitTemplate")
    private AsyncRabbitTemplate asyncGeneralRabbitTemplate;*/

    @Autowired
    private ExecutorService executorService;
    @Autowired
    private GeneralProcess generalProcess;



    List <RequestPojo> requestPojoGeneral = new ArrayList<RequestPojo>();

    @RabbitHandler
    @Async
    @RabbitListener(containerFactory = "simpleMessageListenerContainerFactory", queues ="BulkSolve_GeneralrequestQueue")
    public void subscribeToRequestQueue(@Payload RequestPojo sampleRequestMessage, Message message) throws InterruptedException {

        long startTime=System.currentTimeMillis();


        //requestPojoGeneral.add(sampleRequestMessage);
        //System.out.println("List size issssss:" +requestPojoGeneral.size() );
        //generalProcess.processRequestObjectslist(requestPojoGeneral);
        generalProcess.processRequestObjects(sampleRequestMessage);

        System.out.println("message in general listener is:" + sampleRequestMessage.getDistance());
        System.out.println("Message payload is:" + sampleRequestMessage);
        System.out.println("Message payload1111 is:" + message );

        //return requestPojoGeneral;

    }


}

我正在我的配置类中实例化上述类

@Bean
    @Scope("prototype")
    public SubscriberGeneralQueue1 SubscriberGeneralQueue1(){
        return new SubscriberGeneralQueue1();
    }

谢谢。

0 个答案:

没有答案
相关问题