Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
自动连线不';t为RESTEasy和Spring 3工作_Spring_Jax Rs_Resteasy_Autowired - Fatal编程技术网

自动连线不';t为RESTEasy和Spring 3工作

自动连线不';t为RESTEasy和Spring 3工作,spring,jax-rs,resteasy,autowired,Spring,Jax Rs,Resteasy,Autowired,在RESTEasy 2.2.1.GA和Spring 3.0.5.RELEASE中使用@Autowired时遇到问题。我每次都会得到NPE String result = customerBo.getMsg(); 为我服务 如何更正代码的自动连线行为 这是我的RESTEasy服务: @Component @Path("/api") public class Rest { @Autowired CustomerBo customerBo; @GET @P

在RESTEasy 2.2.1.GA和Spring 3.0.5.RELEASE中使用@Autowired时遇到问题。我每次都会得到NPE

String result = customerBo.getMsg();
为我服务

如何更正代码的自动连线行为

这是我的RESTEasy服务:

@Component
@Path("/api")
public class Rest {

    @Autowired
    CustomerBo customerBo;

      @GET
      @Produces("text/plain")
      public String getXMLMessage() {
              String result = customerBo.getMsg();
              return result;
      }
}
这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/root-context.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- JBoss RESTEasy -->
    <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>ua.softserve.hotel.api.Rest</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/api</url-pattern>
    </servlet-mapping>
    <!-- JBoss RESTEasy end -->

    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>charsetFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>charsetFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

上下文配置位置
/WEB-INF/spring/root-context.xml
org.springframework.web.context.ContextLoaderListener
resteasy.resources
ua.softserve.hotel.api.Rest酒店
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
RESTEasyServlet
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
RESTEasyServlet
/原料药
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/appServlet/servlet-context.xml
1.
appServlet
/
字符集过滤器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
字符集过滤器
/*
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
这是我的root-context.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" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <!-- Root Context:   -->

    <context:annotation-config />

    <bean id="customerBo" class="ua.softserve.hotel.api.CustomerBoImpl">
    </bean>

    <context:component-scan base-package="ua.softserve.hotel" />

    <import resource="data.xml" />
    <import resource="security.xml" />

</beans>

我的问题解决了。 问题是,对于实现,我使用了来自不同版本库的不同来源的文章

我在官方文件中找到了我的问题的正确答案:

根据文档,SpringContextLoaderListener必须在ResteasyBootstrap之后声明,因为它使用由它初始化的ServletContext属性

org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap

org.jboss.resteasy.plugins.spring.SpringContextLoaderListener

你能发布你的web.xml吗?你不应该等太久。这是一个研究项目,所以它仍然可以包含错误。最后一个版本放在这里:我已经像你一样评论了行代码
,但这是正确的方式吗?是的,RESTEasy使用自己的
org.jboss.RESTEasy.plugins.spring.SpringContextLoaderListener
我可以知道你是如何解决这个问题的吗?实际上,我不能使用自动连线。我必须依赖于使用applicaton的上下文获取bean实例。我认为在您的情况下,您最好创建新的问题。顺致敬意,