Spring consolidation jersey The problem of not injecting service

Source: Internet
Author: User

Phenomenon:

@autowired injection service or DAO failed in action, NULL pointer exception

Reason:

The reason for this problem is that you are not doing a good job of integrating spring and jersey, checking your web.xml files, Jersey configuration is certainly the following,

<servlet>
    <servlet-name>JerseyServlet</servlet-name>
	<servlet-class> com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class>
	<init-param>
		< Param-name>com.sun.jersey.config.property.packages</param-name>
		<param-value>com.demo</ param-value>
	</init-param>
	<load-on-startup>1</load-on-startup>
</ servlet>
<servlet-mapping>
	 <servlet-name>JerseyServlet</servlet-name>
	 < Url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Solutions:

First you need to confirm whether the Jersey-spring.jar jar package has been introduced, and if not, import it first.

Second, change the configuration of the jersey to the following,

<servlet>
        <servlet-name>JerseyServlet</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.demo </param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
</ servlet>
<servlet-mapping>
        <servlet-name>JerseyServlet</servlet-name>
        < Url-pattern>/rest/*</url-pattern>
</servlet-mapping>

As you may have seen, the difference lies in the Servlet-class class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.