2012-12-22 20 views
0

我對測試工作的例子通過創建配置並創建了所有必要的文件spring3寧靜project.i但是當我開始我的服務器我得到下面的錯誤-----獲取服務器上自動裝配春天開始的錯誤

org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486) 
     at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92) 
     Truncated. see log file for complete stacktrac 



    --------------------applicationContext.xml file-------------------------- 
    below is my applicationContext.xml file 

    <?xml version="1.0" encoding="UTF-8"?> 


    <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:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd 
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <!-- Activates various annotations to be detected in bean classes--> 
    <context:annotation-config /> 

    <!-- Scans the classpath for annotated components that will be auto-registered as Spring beans. 
    For example @Controller and @Service. Make sure to set the correct base-package --> 
    <context:component-scan base-package="org.nea.rest.abc" /> 
    <context:component-scan base-package="org.nea.spring.services.interfaces.test" /> 


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

    <!-- Configures the annotation-driven Spring MVC Controller programming model. 
    Note that, with Spring 3.0, this tag works in Servlet MVC only! --> 
    <mvc:annotation-driven /> 

    </beans> 

    -------------------------<abc>-servlet.xml file(spring bean) file------------------- 

    <?xml version="1.0" encoding="UTF-8"?> 

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

    <!-- Specify a view resolver for JSP files--> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
    p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> 

    </beans> 


    -----------------------java file --------------------------- 
下面

是我做了我的方法的文件,我已經通過寧靜

package org.nea.rest.unsr; 

    import java.util.ArrayList; 
    import java.util.List; 

    import org.apache.commons.logging.Log; 
    import org.apache.commons.logging.LogFactory; 

    import org.springframework.beans.factory.annotation.Autowired; 
    import org.springframework.stereotype.Component; 
    import org.springframework.stereotype.Controller; 
    import org.springframework.web.bind.annotation.PathVariable; 
    import org.springframework.web.bind.annotation.RequestMapping; 
    import org.springframework.web.bind.annotation.RequestMethod; 
    import org.springframework.web.bind.annotation.ResponseBody; 

    @Controller 
+2

錯誤消息很明顯:*沒有匹配的類型爲[org.nea.spring.services.interfaces.u niservs.UniservSearchInterface]找到依賴關係*。 Spring bean在哪裏實現這個'UniservSearchInterface'接口? –

+0

Hi Nizet。我已經編輯了我的界面和實現類,請檢查相同。 – user1913611

+1

實現類必須是Spring bean。可以通過在XML文件中聲明它,也可以用Spring註釋(例如組件或服務)註釋它。 –

回答

1

揭露擴展在@jbnizet評論... 「實現類必須通過宣佈它是一個Spring bean。無論是XML文件,或通過使用Spring註釋進行註釋(例如組件或服務)「。

您可以添加這appContext:

<context:component-scan base-package="com.yourbasepackage"/> 

,將允許您添加annoation

@Service("uniservService") 
public class UniservServiceJPAImpl implements UniservSearchInterface { 
} 

,然後你可能也希望這些爲更全面的註釋處理:

<!--Indicates that transaction configuration is defined by Java 5 
    annotations on bean classes --> 
<tx:annotation-driven transaction-manager="yourtransactionManager"/> 

<!-- Activates various annotations to be detected in bean classes: Spring's @Required and 
    @Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available) --> 
    <context:annotation-config/> 
+0

HI Nim我包含了註釋,現在錯誤是其他東西。我可以猜測問題出在哪裏。爲我的SpringServices,SpringServicesImpl創建了不同的項目,併爲我的工作空間中的多個項目複製了這兩個jar文件,並將其作爲spring.jar和springservice.jar.now複製到了我的項目中,然後創建了一個jar文件,現在你能告訴我如何在我的springRest項目中複製相同的jar,或者我必須在我的build.xml文件中添加什麼行,以便我可以將這兩個jar複製到lib文件夾的不同項目中 – user1913611