gpt4 book ai didi

java - Spring PropertyPlaceHolder 问题

转载 作者:行者123 更新时间:2023-11-30 03:22:17 27 4
gpt4 key购买 nike

我正在使用 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 声明已注入(inject)其值。我能够通过调试应用程序来验证这一点。仅 imiClient bean 实例未注入(inject)。

<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

最佳答案

终于,我解决了这个问题。显然,我的类路径上有几个应用程序未使用的 spring jar,因此我清理了它们并注入(inject)了正确的值而不是占位符。

关于java - Spring PropertyPlaceHolder 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31063301/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com