的暴露bean我正在創建一個將從jar文件使用類的戰爭。 現在這個jar文件在其associationApplicationContext.xml
中公開了一個bean,它在其某些屬性上使用@Required註釋進行初始化。無法使用使用RequiredAnnotationBeanPostProcessor
associationApplicationContext.xml
例如
<!-- processes @Required annotations-->
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
<!-- The client bean to access the association rest web service -->
<bean id="associationClient" class="com.springtest.client.AssociationClientImpl">
<property name="associationRestClient" ref="associationServiceRestClient" />
</bean>
所以AssociationClient
內的財產associationRestClient
有@Required
標籤在其setter方法。現在
@Required
public void setAssociationRestClient(final AssociationRestClient associationRestClient) {
this.associationRestClient= associationRestClient;
}
,因爲當我嘗試在我的戰爭文件中使用這個bean -
我已經把JAR依賴於戰爭文件的pom.xml 已經把contextConfigLocation
在web.xml
爲
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/associationApplicationContext.xml
</param-value>
</context-param>
從WAR文件裏的另一個applicationcontext.xml
文件中使用bean作爲
<import resource="classpath:/associationApplicationContext.xml"/>
<bean id="requestHandlerV1"
class="com.springtest.application.RequestHandlerV1">
<property name="associationClient" ref="associationClient"></property>
</bean>
這裏的物業associationClient
是沒有得到初始化,因爲它無法找到參考豆associationRestClient
這是associationServiceRestClient
我越來越
org.springframework.beans.factory.NoSuchBeanDefinitionException:無豆命名'associationServiceRestClient'被定義爲
如何獲得associationClient
的對象在這裏初始化?
PS:我不能改變它採用@Required註釋
在導入資源中,是不是類路徑:/associationApplicationContext.xml.xml(.xml.xml)是一個錯字? – Prasad
修改了它。但這僅僅是一個例子。我不能把原始文件。 – Vishal
您可以從web.xml中將applicationcontext.xml設置爲servlet的配置參數嗎? – Prasad