2013-03-08 82 views
0

我正在開發一個Spring項目:Common在XML中使用Annotaions和Spring IOC的組合。 我有一個common.jar,其中包含各種項目使用的Common類。contex:組件掃描不拾取在jar文件中定義的bean

我還有另一個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 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"); 

      ..... 
    } 

} 

如果您需要查看任何其他文件的代碼,請讓我知道。

+0

? – beny23 2013-03-08 16:32:57

+0

我正在使用Spring 3.1 – user1614808 2013-03-08 17:51:36

+0

@ user1614808:今天我有完全相同的問題。在webap spring.xml中顯式定義的bean被正確拾取,而依賴項jar中的任何註釋的bean都沒有。你有沒有找到解決方案? – 2014-09-03 15:54:45

回答

0

那麼您使用的這些春天的版本中添加這applicationContext.xml

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

Spring MVC不是這些嗎? Common.jar有一些常用的類,它們被幾個不是Spring MVC項目的項目使用 – user1614808 2013-03-11 03:13:59