Results 1 to 4 of 4

Thread: read jndi Environment with @Value annotation, spring 3.1.2.FINAL

  1. #1
    Join Date
    Feb 2005
    Posts
    19

    Default read jndi Environment with @Value annotation, spring 3.1.2.FINAL

    I'm re-factoring properties from an application's property file (read using ServletContextPropertyPlaceholderConfigurer ) to an application tomcat context file. I'd like to continue to read these properties in my java code using @Value annotation, e.g.

    @Component
    @Singleton
    @Path("subscription/v1")
    public class SubscriptionAdapter {

    @Value("${subscription.endpoint}" )
    private String endpointurl = null; //
    }


    When spring tries to inject the @Value("${subscription.endpoint}" ) at runtime I get :

    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'subscriptionAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private java.lang.String com.sas.ost.widget.service.SubscriptionAdapter.end pointurl; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'subscription.endpoint' in string value [${subscription.endpoint}]
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessPropert yValues(AutowiredAnnotationBeanPostProcessor.java: 287)

    ... etc

    ===
    ===
    ===

    Additional context:
    Tomcat context file defines props using "Environment".

    <Environment name="subscription.endpoint" value="http://blah.com/stuff/" type="java.lang.String" override="false"/>


    I have the annotation :

    <contextroperty-placeholder />

    I see that JndiPropertySource.getProperty is called for other properties in my spring context file, for example "${SOMETHING}" below:

    <bean class="org.springframework.web.context.support.Ser vletContextPropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="searchContextAttributes" value="true"/>
    <property name="contextOverride" value="true"/>
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="locations">
    <list>
    <value>classpath:common_foo_${SOMETHING}.propertie s</value>
    <value>classpath:local.properties</value>
    </list>
    </property>
    </bean>

  2. #2
    Join Date
    Jul 2012
    Posts
    4

    Default

    Hi,

    if you are accessing props other than controllers then you have to specify "PlaceholderConfigurer" in application config.

    I hope this might solve your problem.

    Regards,
    Pulin

  3. #3
    Join Date
    Feb 2005
    Posts
    19

    Default

    Quote Originally Posted by pulin View Post
    Hi,

    if you are accessing props other than controllers then you have to specify "PlaceholderConfigurer" in application config.

    I hope this might solve your problem.

    Regards,
    Pulin
    Thanks pulin! However, I'm still not clear how to do this... I've seen several examples of using PropertyPlaceholderConfigurer to use a property file whose name was read from jndi (e.g. tomcat conext file).

    What I'm trying to do is specify all my properties as Environment entries in my tomcat context file... At this point I don't think that's possible

  4. #4
    Join Date
    Feb 2005
    Posts
    19

    Default

    ...and the answer is, it works just fine. I just needed to specify my properties as context parameters instead of environment, e.g. tomcat context file as:

    <Context path="/applicationname"
    debug="1"
    privileged="false">

    <Parameter name="subscription.endpoint" value="http://foo.com/bar/" override="false"/>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •