context:component-scan没有拾取jar文件中定义的bean

时间:2013-03-08 16:20:52

标签: spring jar annotations

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

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

由于某些原因,我的WebService项目没有选择在Common.jar中使用@Component Annotation标记的bean。但是使用< bean id =""定义了所有bean。类="" />在Common.jar中被选中了。

以下是所有必要配置文件的代码。真的很感谢你的帮助。提前谢谢。

在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 Project,Ipd​​Service_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");

           .....
    }

}

如果您需要查看任何其他文件的代码,请与我们联系。

1 个答案:

答案 0 :(得分:0)

将此添加到applicationContext.xml

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>