gpt4 book ai didi

java - 服务器启动时出现 spring Autowiring 错误

转载 作者:行者123 更新时间:2023-12-01 14:58:38 25 4
gpt4 key购买 nike

我正在通过创建 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

最佳答案

扩展@jbniset 评论...“实现类必须是 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/>

关于java - 服务器启动时出现 spring Autowiring 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14001390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com