【问题标题】:access application context within @Endpoint Spring WS 1.5在@Endpoint Spring WS 1.5 中访问应用程序上下文
【发布时间】:2012-09-19 23:24:46
【问题描述】:

我想从我的端点处理程序方法中访问我在 /WEB-INF/springws-servlet.xml 中定义的 bean。目前我正在诉诸如下图。有没有更好的方法来访问上下文以在 Endpoint 中获取 bean。

ApplicationContext ctx = new FileSystemXmlApplicationContext("webapp/WEB-INF/springws-servlet.xml");

BeanType mybean = (BeanType) ctx.getBean("mybean");

jaxb2marshaller 也是如此。我在 springws-servlet.xml 中设置了它。如何在我的 Endpoint 中访问它而不是这样做

JAXBContext jc = JAXBContext.newInstance("com.test.mypackage");
Marshaller m = jc.createMarshaller();

下面是我的webapp/WEB-INF/springws-servlet.xmlwebapp/WEB-INF/springws-servlet.xml

  <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
    <constructor-arg ref="jaxbmarshaller"/>
  </bean>

  <bean id="endpointMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>


  <bean id="jaxbmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>org.hr_xml._3.SyncHRMasterDataType</value>
            <value>org.openapplications.oagis._9.ConfirmBODType</value>
        </list>
    </property>
  </bean>



  <bean id="mybean" class="com.test.package">
    <property name="releaseID" value="1"/>
  </bean>

非常感谢。

【问题讨论】:

    标签: web-services spring spring-mvc spring-ws


    【解决方案1】:

    您应该只在端点内自动装配您的依赖项:

    class MyEndPoint{
    
      @Autowired MyBean mybean
    ..
    }
    

    【讨论】:

    • 当使用注解注入 bean 时,你也应该看看 Spring 中的 @Configuration 类!这会更加简化。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多