Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @自动连线不';使用带有弹簧的球衣时,不起作用_Java_Spring_Jersey_Jax Rs - Fatal编程技术网

Java @自动连线不';使用带有弹簧的球衣时,不起作用

Java @自动连线不';使用带有弹簧的球衣时,不起作用,java,spring,jersey,jax-rs,Java,Spring,Jersey,Jax Rs,我试着用带有弹簧的球衣。但就我个人而言,我不明白为什么我的Spring依赖项没有被注入到我的Rest类中 每次我尝试调用自动连线依赖项时,都会得到NULL。谁能告诉我为什么我的依赖性没有被注入 我的休息课是这样的: com.myapp.rest @Component @Scope("request") @Path("/home") public class ChartResource { @Autowired ChartService chartService; @GET @Path("

我试着用带有弹簧的球衣。但就我个人而言,我不明白为什么我的Spring依赖项没有被注入到我的Rest类中

每次我尝试调用自动连线依赖项时,都会得到NULL。谁能告诉我为什么我的依赖性没有被注入

我的休息课是这样的:

com.myapp.rest

@Component
@Scope("request") 
@Path("/home")
public class ChartResource {

@Autowired
ChartService chartService;

@GET
@Path("/chart")
@Produces(APPLICATION_JSON)
public Bean getChart() {
        return chartService.retrieveChart();


}
我的web.xml文件如下所示

<servlet>
    <servlet-name>myapp</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>org.codehaus.jackson.jaxrs;com.myapp.rest</param-value>
    </init-param>       
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>org.codehaus.jackson.jaxrs</param-value>
    </init-param>   
    <load-on-startup>1</load-on-startup>
</servlet>

myapp
com.sun.jersey.spi.spring.container.servlet.SpringServlet
com.sun.jersey.config.property.packages
org.codehaus.jackson.jaxrs;com.myapp.rest
com.sun.jersey.config.property.packages
org.codehaus.jackson.jaxrs
1.
My applicationContext.xml是标准的,并指定用于组件扫描的基本包:

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

<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />


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

</beans:beans>

尝试添加

<context:annotation-config />


我不确定您需要什么才能让Jersey的注释正常工作,但是
@Autowired
是一个Spring注释,所以您需要使用
的Spring版本才能使其正常工作。

好的-愚蠢的问题。我的applicationContext没有被加载,因此它没有拾取我为组件扫描定义的包

请发布applicationContext.xml文件。通常是“标准”的东西打破了东西。另外,请发布剩余课程的软件包嗨,克里斯,我已经添加了课程的完整应用程序上下文和软件包。谢谢克里斯。碰巧我很笨,我的applicationContext.xml在web.xml中没有被正确引用。修正参考修正了它。如果这确实是问题所在,你应该将其标记为正确答案(通过点击答案旁边的空心复选标记)。它帮助其他搜索同类问题的人,让他们知道是的,这确实是修复方法。你能澄清一下我的applicationContext没有被加载吗