【发布时间】:2015-06-26 01:07:43
【问题描述】:
我正在使用 Spring 4.1.5.RELEASE。在上下文文件加载中,而不是从属性文件中的条目中解析占位符,它只是将占位符条目直接插入到 bean 中。
上下文文件
<context:property-placeholder
location="classpath*:META-INF/spring/*.properties,classpath*:conf/*.properties"
ignore-resource-not-found="true"/>
<jaxws:client id="imiClient"
serviceClass="com.imi.ws.mail.MailPortType"
address="${imi.ws.fulfillment.service}">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
</jaxws:outInterceptors>
</jaxws:client>
<http:conduit name="*.http-conduit">
<http:tlsClientParameters disableCNCheck="true"/>
</http:conduit>
属性文件
imi.ws.fulfillment.service=http://localhost:8076/Mail/MailWebService
每当我在创建的 bean 上调用 Web 方法时,都会出现以下异常
Caused by: java.net.URISyntaxException: Illegal character in path at index 1: ${imi.ws.fulfillment.service}
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parseHierarchical(URI.java:3105)
at java.net.URI$Parser.parse(URI.java:3063)
at java.net.URI.<init>(URI.java:588)
at org.apache.cxf.transport.http.HTTPConduit.setupURI(HTTPConduit.java:664)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:458)
... 45 more
占位符 ${imi.ws.fulfillment.service} 未解析。我尝试调试应用程序并意识到属性文件确实是加载程序,并且所有其他条目都可用。
我使用了 @Value 注释,得到了预期的结果。 任何帮助将不胜感激。提前致谢。
更新
其他带有占位符的 bean 声明已注入其值。我能够通过调试应用程序来验证这一点。只有 imiClient bean 实例没有被注入。
<bean id="encryptorDecryptor" class="com.mail.util.EncryptorDecryptor" factory-method="getInstance">
<constructor-arg index="0" type="String" value="${encryption.cert.location}"/>
<constructor-arg index="1" type="String" value="${encryption.cert.duration}"/>
<constructor-arg index="2" type="String" value="${props}"/>
</bean>
属性文件
encryption.cert.location=${file.basedir}\\EncryptionCert\\enc.cert
encryption.cert.duration=10
props=META-INF/spring/mail.properties
【问题讨论】:
-
这行不通。在命名空间中使用属性时,必须在命名空间中明确支持它,如果没有,它将无法工作。作为一种解决方法,您不能使用命名空间并手动从 jax-ws 客户端配置所有内容。
-
这一直有效,直到昨天,但是您能否详细说明您谈到的名称空间以及您提出的工作。
-
不,差不多就是这样。如果命名空间不支持占位符,那么您无能为力。占位符必须被命名空间解析后面的
BeanDefinitionParsers 替换,如果不是,则不会发生任何事情。解决方法是,放弃命名空间的使用,弄清楚它的作用并手动配置所有 bean.. -
感谢@M.Deinum,我能够通过清理类路径来解决这个问题。我删除了所有未使用的罐子,现在似乎一切正常。