DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS
  • 5 DevOps Tools To Add to Your Stack in 2022
  • Spring Config Integration With a PCF Application: A Step-by-Step Guide
  • Spring Boot - Microservice- JaxRS Jersey - HATEOAS - JerseyTest - Integration

Trending

  • A Guide to Developing Large Language Models Part 1: Pretraining
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • Unlocking the Benefits of a Private API in AWS API Gateway
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Integrate Jersey in a Spring MVC Application

How to Integrate Jersey in a Spring MVC Application

By 
Adrian Matei user avatar
Adrian Matei
·
Jan. 08, 15 · Interview
Likes (0)
Comment
Save
Tweet
Share
19.8K Views

Join the DZone community and get the full member experience.

Join For Free

I have recently started to build a public REST API with Java for Podcastpedia.org and for the JAX-RS implementation I have chosen Jersey, as I find it “natural” and powerful – you can find out more about it by following the Tutorial – REST API design and implementation in Java with Jersey and Spring. Because Podcastpedia.org is a web application powered by Spring MVC, I wanted to integrate both frameworks in podcastpedia-web, to take advantage of the backend service functionality already present in the project. Anyway this short post will present the steps I had to take to make the integration between the two frameworks work.

Framework versions

Current versions used:

<properties>
	<spring.version>4.1.0.RELEASE</spring.version>
	<jersey.version>2.14</jersey.version>
</properties>

Project dependencies

The Jersey Spring extension must be present in your project’s classpath. If you are using Maven add it to the pom.xml file of your project:

<!-- Jersey-Spring http://mvnrepository.com/artifact/org.glassfish.jersey.ext/jersey-spring3/2.4.1 -->
<dependency>
	<groupId>org.glassfish.jersey.ext</groupId>
	<artifactId>jersey-spring3</artifactId>
	<version>${jersey.version}</version>
	<exclusions>
		<exclusion>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
		</exclusion>
		<exclusion>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
		</exclusion>
		<exclusion>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.glassfish.jersey.media</groupId>
	<artifactId>jersey-media-json-jackson</artifactId>
	<version>${jersey.version}</version>
	<exclusions>
		<exclusion>
			<groupId>com.fasterxml.jackson.jaxrs</groupId>
			<artifactId>jackson-jaxrs-base</artifactId>
		</exclusion>		
		<exclusion>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
		</exclusion>
		<exclusion>
			<groupId>com.fasterxml.jackson.jaxrs</groupId>
			<artifactId>jackson-jaxrs-json-provider</artifactId>
		</exclusion>        					
	</exclusions>
</dependency>

Note: I have explicitly excluded the Spring core and the Jackson implementation libraries as they have been already imported in the project with preferred versions.

Web.xml  configuration

In the web.xml, in addition  to the Spring MVC servlet configuration I added the jersey-servlet configuration, that will map all requests starting with/api/:

<servlet>
	<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	
	<init-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:spring/application-context.xml	   			
		</param-value>
	</init-param>
	<load-on-startup>1</load-on-startup>
</servlet>		
<servlet-mapping>
	<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
	<url-pattern>/</url-pattern>
</servlet-mapping>

<servlet>
	<servlet-name>jersey-serlvet</servlet-name>
	<servlet-class>
		org.glassfish.jersey.servlet.ServletContainer
	</servlet-class>
	<init-param>
		<param-name>javax.ws.rs.Application</param-name>
		<param-value>org.podcastpedia.web.api.JaxRsApplication</param-value>			
	</init-param>		
	<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
	<servlet-name>jersey-serlvet</servlet-name>
	<url-pattern>/api/*</url-pattern>
</servlet-mapping>	

Well, that’s pretty much it… If you have any questions drop me a line or comment in the discussion below.

In the coming post I will present some of the results of this integration, by showing how to call one method of the REST public API with jQuery, to dynamically load recent episodes of a podcast, so stay tuned.

Spring Framework Integration application

Published at DZone with permission of Adrian Matei, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS
  • 5 DevOps Tools To Add to Your Stack in 2022
  • Spring Config Integration With a PCF Application: A Step-by-Step Guide
  • Spring Boot - Microservice- JaxRS Jersey - HATEOAS - JerseyTest - Integration

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: