I was also facing same issue such as "None or multiple beans found in Spring context for type class com.ilearn.jersey.resource.HealthCheckResource, skipping the type."
This error occurred due to @RestController annotation applied on resource classes.
Jersey Framework don't need @RestController annotation on controller classes instead of you can use @javax.annotation.Resource. Even it works without @Resource annotation as well.
You need to add you Controller class to register in the JerseyConfig as give example.
*** 1) Your Controller/Resource class ***
package com.ilearn.jersey.resource;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@Path("/health-check")
@Resource
public class HealthCheckResource {
private static final Logger logger = LogManager.getLogger(HealthCheckResource.class);
private static AtomicInteger counter = new AtomicInteger(0);
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response healthCheck() throws JsonProcessingException {
if(counter.incrementAndGet() == 10) {
logger.debug("i-learn application is up, Date: {}", LocalDateTime.now());
counter.set(0);
}
return Response.ok(getStatus()).build();
}
private String getStatus() throws JsonProcessingException {
final Map<String, String> serverStatusMap = new ConcurrentHashMap<>();
serverStatusMap.put("i-learn", "Running");
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(serverStatusMap);
}
}
*** 2) Your JerseyConfig class to register resources ***
package com.ilearn.jersey.config;
import com.ilearn.jersey.resource.AutoCompletionResource;
import com.ilearn.jersey.resource.HealthCheckResource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.context.annotation.Configuration;
import javax.ws.rs.ApplicationPath;
@Configuration
@ApplicationPath("/i-learn")
public class JerseyConfig extends ResourceConfig {
private static final Logger logger = LogManager.getLogger(JerseyConfig.class);
public JerseyConfig() {
logger.info("Registering endpoints classes...");
this.registerEndpoints();
logger.info("Registered endpoints classes");
}
private void registerEndpoints() {
register(HealthCheckResource.class);
register(AutoCompletionResource.class);
}
}
**3) pom.xml:**
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>2.33</version>
</dependency>
</dependencies>
**4) Run application using url:**
http://localhost:8080/i-learn/health-check
Output:
{
"i-learn": "Running"
}