0

我正在开发一个 Spring Project:Common,它在 XML 中使用 Annotaions 和 Spring IOC 的组合。我有一个 common.jar,其中包含各种项目使用的 Common 类。

我还有另一个 Spring Project:WebService 引用 common.jar 中定义的 bean。

由于某种原因,Common.jar 中标有 @Component Annotation 的 bean 没有被我的 WebService 项目拾取。但是在 Common.jar 中使用 <bean id="" class="" /> 定义的所有 bean 都被拾取。

以下是所有具有必要配置的文件的代码。非常感谢您的帮助。提前致谢。

在 Common.jar 中,applicationContext.xml

   <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

    <import resource="springConfig/app/AppServices.xml"/> <!-- Beans in this file were loaded. -->

    <context:annotation-config/>
    <context:component-scan base-package="com.ipd.app1"/> <!-- Beans for all classes under app1 package were NOT loaded  -->

</beans>

在 Common.jar 中,AppServices.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="inquireOrderApp" class="com.ipd.app.inquireOrderDetail.InquireOrderDetailAppImpl"/>

</beans>

Common.jar、com.test.app.MyClass

package com.ipd.app1;
    @Component("createOrderApp")
    public class CreateOrderAppImpl implements CreateOrderApp {
        @Override   
        public CreateOrderResponse processMSSOrder(TransactionContext tx,
                CreateOrderRequest createOrderRequest)
                throws ApplicationException, Exception {

            System.out.println("In App Layer Class CreateOrderAppImpl to ProcessOrder.");
            return response;
        }
    }

WebService 项目,IpdService_IPDSoapHTTPPortImpl.java

 @WebService(portName = "IpdSoapHTTPPort", serviceName = "IpdService", targetNamespace = "http://ipd.com/ipdIpdweb/", wsdlLocation = "/wsdls/Ipd.wsdl", endpointInterface = "com.ipd.ipdIpdweb.IpdPortType")
@BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
public class IpdService_IpdSoapHTTPPortImpl implements IpdPortType {

    ApplicationContext ctx;

    public IpdService_IpdSoapHTTPPortImpl() {
        this.ctx = AppContext.getCtx();
    }

    @Override
    public void createOrder(WSHeader wsHeader,
            CreateOrderRequest createOrderRequest,
            Holder<WSResponseHeader> wsResponseHeader,
            Holder<CreateOrderResponse> createOrderResponse)
            throws WSException {


            CreateOrderApp createOrderApp = (CreateOrderApp) ctx.getBean("createOrderApp");         
            res = createOrderApp.processOrder(tx, createOrderRequest);

            res.setResponseCode(BigInteger.valueOf(0));
            res.setResponseMessage("Success");

           .....
    }

}

如果您需要查看任何其他文件的代码,请告诉我。

4

1 回答 1

0

好吧,将其添加到applicationContext.xml

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
于 2013-03-08T16:44:06.387 回答