0

I am using ignoreUnresolvablePlaceholders in my spring context. as below.

<bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:messaging.properties</value>
            </list>
        </property>
        <property name="ignoreResourceNotFound" value="false" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
    </bean>

event setting ignoreUnresolvablePlaceholders to true its not ignoring my spring bean being injecting. i am passing amq.topic= in property file for

<bean id="messageTopic1" class="org.apache.activemq.command.ActiveMQTopic">
        <constructor-arg value="${amq.topic}" />
</bean>

But its not ignoring this bean for being injecting.

below is my Spring-context.xml amd property file.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:messaging.properties</value>
            </list>
        </property>
        <property name="ignoreResourceNotFound" value="false" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
    </bean>


    <!-- Active MQ Broker Configuration Details -->

    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="${amq.url}" />
    </bean>

    <bean id="messageQueue1" class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg value="${amq.queue}" />
    </bean>

    <bean id="messageTopic1" class="org.apache.activemq.command.ActiveMQTopic">
        <constructor-arg value="${amq.topic}" />
    </bean>

    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="connectionFactory" />
    </bean>

    <bean id="activeMQ" class="com.isc.common.messaging.AmqUtilityHelper">
        <property name="destination" ref="messageQueue1" />
        <property name="jmsTemplate" ref="jmsTemplate" />
    </bean>

    <!-- <bean id="activeMQ1" class="com.isc.common.messaging.AmqUtilityHelper">
        <property name="destination" ref="messageTopic1" />
        <property name="jmsTemplate" ref="jmsTemplate" />
    </bean> -->

    <bean id="messageBroker" class="com.isc.common.messaging.AmqUtilityHelper">
        <property name="activeBroker" value="${active.broker}" />
    </bean>

</beans>

And Below is the property file that i am loading.

#AMQ/Solace properties production:
# uncomment the borker to use
active.broker=activeMQ
#active.broker=solace
#active.broker=activeMQ



#AMQ Broker Properties
amq.url=failover:(tcp://localhost:61616)??initialReconnectDelay=2000&maxReconnectAttempts=5
amq.queue=messageQueue1
amq.topic=


#Solace Broker Properties
solace.url=smf://192.168.56.101:55555
solace.userName=spring_user@Solace_Spring_VPN
solace.passWord=spring_password
solace.jndiName=JNDI/CF/spring1
solace.queue=JNDI/Q/requests
#solace.topic=JNDI/topic1
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

By default, ApplicationContext implementations eagerly create and configure all singleton beans as part of the initialization process. Generally, this pre-instantiation is desirable, because errors in the configuration or surrounding environment are discovered immediately, as opposed to hours or even days later. When this behavior is not desirable, you can prevent pre-instantiation of a singleton bean by marking the bean definition as lazy-initialized. A lazy-initialized bean tells the IoC container to create a bean instance when it is first requested, rather than at startup.

Can you please try to lazily initialize your bean using below construct.

lazy-init="true"

   <bean id="messageTopic1" class="org.apache.activemq.command.ActiveMQTopic" 
  lazy-init="true">
            <constructor-arg value="${amq.topic}" />
    </bean>
Mahesh_Loya
  • 2,743
  • 3
  • 16
  • 28
  • Its working if i comment out spring bean. But i dont want to comment out bean which is refering to bean id="messageTopic1" so how to stop lazy-init="true" spring bean being refereed by other spring beans. – saurabh mahajan Jun 22 '18 at 05:14