Reputation: 10584
I am writing a Spring Boot application with a REST service based on jersey.
My repository interface is as below
@Repository
public interface ConnectionRepository extends CrudRepository<Connection, Integer>
{
}
My REST service is as follows
@Component
@Path("/conn")
public class ConnectionService
{
@Autowired
private ConnectionRepository cer;
@GET
@Path("/{id}/")
@Produces(MediaType.APPLICATION_JSON)
public Response getSpConnection(@PathParam("id") String tid) throws Exception
{
Gson gson = new Gson();
if(cer == null)
{
return Response.status(Response.Status.OK).entity("Hello World").build();
}
Connection conendpoint = cer.find(tid);
if(conendpoint == null)
{
return Response.status(Response.Status.NOT_FOUND).build();
}
else
{
String jsonConn = gson.toJson(conendpoint);
return Response.status(Response.Status.OK).entity(jsonConn).build();
}
}
}
Application.java
@EnableAutoConfiguration
@SpringBootApplication
@ComponentScan
@Component
@PropertySource("classpath:/application.properties")
@Import(PersistenceContext.class)
public class Application extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<Application> applicationClass = Application.class;
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
}
PersistenceContext contains information for datasource and other beans.
Whenever I access this REST service, I get ConnectionRepository as null and the response is "Hello World". I am using spring-boot-starter-web
,spring-boot-starter-jersey
and spring-boot-starter-data-jpa
.
What am I missing?
Upvotes: 1
Views: 1226
Reputation: 10584
I solved this problem by adding following dependency in my pom.xml
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.23.2</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<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>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
Upvotes: 1