java - 使用 Spring @Value 注解时禁用 JndiProperty 源

标签 java spring properties jndi

我有一个 Spring 应用程序,配置为在 xml 上有一个属性文件配置

 <context:property-placeholder location="classpath:app.properties"/>

我有一些类可以使用 @Value 注释从此处查找值。 然而,每次我在没有 java 应用程序服务器 (Websphere) 的情况下运行 junit 测试时,都需要一段时间来查找值,例如每个字段 1 秒。 打开 DEBUG 模式表明是 JNDI 查找导致的。

2016-09-23 17:50:29,462{ISO8601 [P=25904:O=0:CT] org.springframework.core.env.PropertySourcesPropertyResolver DEBUG  - Searching for key 'spring.liveBeansView.mbeanDomain' in [servletConfigInitParams]
2016-09-23 17:50:29,462{ISO8601 [P=25904:O=0:CT] org.springframework.core.env.PropertySourcesPropertyResolver DEBUG  - Searching for key 'spring.liveBeansView.mbeanDomain' in [servletContextInitParams]
2016-09-23 17:50:29,462{ISO8601 [P=25904:O=0:CT] org.springframework.core.env.PropertySourcesPropertyResolver DEBUG  - Searching for key 'spring.liveBeansView.mbeanDomain' in [jndiProperties]
2016-09-23 17:50:29,462{ISO8601 [P=25904:O=0:CT] org.springframework.jndi.JndiTemplate DEBUG  - Looking up JNDI object with name [java:comp/env/spring.liveBeansView.mbeanDomain]
Sep 23, 2016 5:50:29 PM null null
**SEVERE: javaAccessorNotSet**
2016-09-23 17:50:29,463{ISO8601 [P=25904:O=0:CT] org.springframework.jndi.JndiLocatorDelegate DEBUG  - Converted JNDI name [java:comp/env/spring.liveBeansView.mbeanDomain] not found - trying original name [spring.liveBeansView.mbeanDomain]. javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
2016-09-23 17:50:29,463{ISO8601 [P=25904:O=0:CT] org.springframework.jndi.JndiTemplate DEBUG  - Looking up JNDI object with name [spring.liveBeansView.mbeanDomain]
2016-09-23 17:50:30,474{ISO8601 [P=25904:O=0:CT] org.springframework.jndi.JndiPropertySource DEBUG  - JNDI lookup for name [spring.liveBeansView.mbeanDomain] threw NamingException with message: Could not obtain an initial context due to a communication failure. Since no provider URL was specified, the default provider URL of "corbaloc:iiop:1.0@mymachine:2809/NameService" was used.  Make sure that any bootstrap address information in the URL is correct and that the target name server is running.  Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration.. Returning null.

从属性文件获取值没有问题。

我需要帮助找到配置应用程序以跳过 jndi 查找的最佳方法

最佳答案

我创建了一个 spring.properties文件并添加该值 spring.jndi.ignore=true

关于java - 使用 Spring @Value 注解时禁用 JndiProperty 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39670710/

相关文章:

java - Struts2 javabean 和 setter

java - 如何在 JTable 中显示带有 blob 的数据库表

objective-c - 委托(delegate)属性声明中的 'weak'和 'assign'有什么区别

javascript:如何访问静态属性

java - 一个数据库中的表可以为不同数据库中的另一个表声明一对多声明吗

c# - 如何为 PDF 模板创建签名字段?

java - 使用JUnit测试DAO类时,无法在DB2 10.5中获得下一个序列值

java - 不同 RDBMS 上的 NamedParameterJDBCTemplate 和函数语法

java - 是否有可能将内部联接选择结果转换为嵌套列表 JSON?

objective-c - 隐藏由可变数据支持的不可变属性并支持 Objective-C 中符合 KVO 的集合的最佳模式是什么?