在多场spring-ws服务之间共享应用程序上下文

时间:2018-05-07 12:04:34

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

我正在使用spring-ws进行基于SOAP的Web服务开发,根据我的项目设计,我可以设计多个服务,所以我将更简洁的服务打包成WAR文件,我在一个EAR中打包了总共10个war文件文件,请在下面找到我的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并且我已经尝试了上下文:component-scan用于各个applicationContext-services * .xml中的常见jar&#39;

1 个答案:

答案 0 :(得分:0)