【问题标题】:Sharing an application context between multiple wars of spring-ws services在 spring-ws 服务的多个战争之间共享应用程序上下文
【发布时间】:2018-05-07 12:04:33
【问题描述】:

我正在使用 spring-ws 进行基于 SOAP 的 Web 服务开发,根据我的项目设计,我设计了多个服务,所以我将更精简的服务打包到 WAR 文件中,我总共有 10 个 WAR 文件打包在一个 EAR 中文件,请在下面找到我的 EAR 结构。

MYServices.ear
|
|
|
-------APP-INF/lib
        |
        --------- All *.jar files includes DAO,Services,Exceptions
|
|
----------META-INF
            |
            --------application.xml
            --------weblogic-application.xml
            --------MANIFEST.MF
|
-------- service1.war
           |
            --------META-INF
                      |--------MANIFEST.MF (Class-Path: of all the jar's in APP-INF/lib in ear file)
            --------WEB-INF
                      |--------classes
                      |--------lib(empty)
                      |--------applicationContext-service1.xml
                      |--------serviceWs-servlet1.xml
                      |--------web.xml
                      |--------weblogic.xml


-------- service2.war
           |
            --------META-INF
                      |--------MANIFEST.MF (Class-Path: of all the jar's in APP-INF/lib in ear file)
            --------WEB-INF
                      |--------classes
                      |--------lib(empty)
                      |--------applicationContext-service2.xml
                      |--------serviceWs-servlet2.xml
                      |--------web.xml
                      |--------weblogic.xml

我已经将我所有的数据库操作和异常处理都写在一个单独的 jar 文件中并放置在 EAR(APP-INF/lib) 位置中,这对于所有服务都是通用的,我正在尝试在应用程序中加载我的数据库 jar上下文级别,所以我按照下面的 URL 将它们加载到应用程序上下文级别。

https://spring.io/blog/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/

我的服务的 web.xml 文件被跟踪。

<display-name>Services1</display-name>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/applicationContext-service1.xml</param-value>
</context-param>
<context-param>
    <param-name>locatorFactorySelector</param-name>
    <param-value>classpath:beanRefContext.xml</param-value>
</context-param>

<context-param>
    <param-name>parentContextKey</param-name>
    <param-value>ear.context</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>serviceWs</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
        <param-name>transformWsdlLocations</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>

我的 beanRefContext.xml 被跟踪了。

<bean id="ear.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <constructor-arg>
        <list>
            <value>DataAccess-applicationContext.xml</value>
        </list>
    </constructor-arg>
</bean>

请在下面找到我的示例端点类。

@Endpoint
@Scope("prototype")
public class SampleEndPoint {

    @Autowired
    SampleService sampleService;


    @PayloadRoot(namespace = "http://service.service.com/provider/sample/test/test/2018/05/", localPart = "sampleService")
    @ResponsePayload
    public SampleServiceResponse gpoReleaseBatch(@RequestPayload SampleService sampleService, MessageContext messageContext) {
        System.out.println(sampleService.sayHello("Hi Hello"));
        return null;

    }

}

我的所有服务都有类似的结构,当我将耳朵部署到 weblogic12C 中时,我遇到了异常

Unsatisfied dependency expressed through field 'sampleService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'springshare.SampleService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:367)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1340)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'springshare.SampleService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1502)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1099)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1060)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:578)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
    Truncated. see log file for complete stacktrace

注意:Spring 版本是 5.0.2,我已经尝试了 context:component-scan 用于单个 applicationContext-services*.xml 中的公共 jar

【问题讨论】:

  • 我看到这适用于 spring4.X 版本,而 Spring5.X 则此功能已停止。

标签: java-8 weblogic12c spring-jdbc spring-ws


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 2017-08-17
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    • 2023-04-07
    相关资源
    最近更新 更多