0

我正在通过创建 spring3 restful 项目来处理测试示例。我配置并创建了所有必要的文件,但是当我启动我的服务器时,我得到了以下错误-----

    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 ---------------------------

下面是我制作方法的文件,我必须通过 restful 公开

    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
4

1 回答 1

1

扩展@jbnizet 评论...“实现类必须是 Spring bean。通过在 XML 文件中声明它,或者使用 Spring 注释(例如组件或服务)对其进行注释。”

您可以将其添加到 appContext :

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

这将允许您添加注释

@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/>
于 2012-12-22T09:35:28.613 回答