Jersey + Spring 依赖注入出现 空异常

时间:2015-03-13 19:10:39   收藏:0   阅读:7592

在使用rest风格和Spring的依赖注入做一个demo的时候。依赖注入 老是出现空异常。

 The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerException

   就是没有 注入过去。。。

网上查了查。终于找都一种办法了。

http://www.cnblogs.com/qunyang/p/3328561.html


 引用博主的原文:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

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

    <servlet>
        <servlet-name>jersey-serlvet</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>com.mkyong.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

这里有一点需要注意


但是我使用的是 REST服务类型的另外一种,就是 存在Application 子类,不存在ApplicationPath注解。。我的下面写的这种办法我还是没有解决。大家会的帮个忙

public class ConfigApplication extends Application {

	@Override
	public Set<Class<?>> getClasses() {
		Set<Class<?>> classes = new HashSet<Class<?>>();
		classes.add(ServiceConfig.class);
		classes.add(ServerSerivce.class);
		classes.add(QiniuService.class);
		return classes;
	}
}




评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!