Read an environment variable from applicationContext.xml

前端 未结 4 684
不思量自难忘°
不思量自难忘° 2021-01-02 15:42

I need read an environment variable defined in my web.xml


    Path Repositorio NFS
    

        
4条回答
  •  情书的邮戳
    2021-01-02 16:08

    You can lookup JNDI entries (both environment entries and resources) with the JndiObjectFactoryBean or :

    
    

    (To use the jee-namespace, you must declare it).

    That defines a spring bean named "PATH_ENV" that contains (as a string) the path configured int the environment entry. You can now inject it into other beans:

    
        
    
    

    The remaining difficulty is concatenating the strings. (Unfortunately, there is no JndiPlaceholderConfigurer that would replace placeholders with JNDI environment entries, so you can't use the ${property}/foo syntax to concatenate, and must supply yet another bean definition:

    
        
            
                /myprop.properties
            
        
    
    

    (code untested as I don't have a Spring project at hand to test it)

提交回复
热议问题