I am trying to use a MongoRepository, but Spring complains, that no instance of the MonoRepository-Interface is in the context.
#SpringBootApplication
public class BackendApplication {
public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
}
}
#Document(collection = "tableItems")
class TableItem {
#Id
public String id;
public int roundNbr;
}
interface TableItemsRepository extends MongoRepository<TableItem, String> {
}
#Service
class TableItemsService {
#Autowired
public TableItemsService(TableItemsRepository tableItemsRepository) {
}
}
The server complains:
Parameter 0 of constructor in backend.TableItemsService required a bean of type 'backend.TableItemsRepository' that could not be found.
Action:
Consider defining a bean of type 'backend.TableItemsRepository' in your configuration.
my maven pom.xml:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.4.0</version>
</dependency>
How can I get a bean instance of my MongoRepository?
The dependency is incorrect.
spring-data-mongodb only makes it compile:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.4.0</version>
</dependency>
But you need additional dependencies, to make it run. For convenience you can import spring-boot-starter-data-mongodb, which will import all required artifacts as transitive dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
Related
I am setting up a new Spring project for some fun learning/tutorial at home and I seem to run into a fairly common issue but I have tried all possible solutions I found on here but with no luck. Basically what I have is as follows:
Controller class:
#RestController
#RequestMapping(value = "/shop")
public class ShopController {
#Autowired
ShopService shopService;
#GetMapping(value = "/{id}")
public #ResponseBody Shop getTestData(#PathVariable String id) {
return shopService.getShopBasedOnId(id);
}
}
Service class:
#Service
public class ShopService {
#Autowired
private ShopRepository shopRepository;
public ShopService(ShopRepository shopRepository){
this.shopRepository = shopRepository;
}
public Shop getShopBasedOnId(String id) {
return shopRepository.findByShopId(id);
}
}
Repository class:
#Repository
public interface ShopRepository extends PagingAndSortingRepository<Shop, String> {
Shop findByShopId(String shopId);
}
Application class:
#SpringBootApplication
#EnableJpaRepositories("com.example.reservations.repository")
public class ReservationsApplication {
public static void main(String[] args) {
SpringApplication.run(ReservationsApplication.class, args);
}
}
Last but not least my pom.xml with the dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>
So the error code I am getting is as follows:
Description:
Parameter 0 of constructor in com.example.reservations.services.ShopService required a bean of type 'com.example.reservations.repository.ShopRepository' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.example.reservations.repository.ShopRepository' in your configuration.
My structure of folders is:
main
|_java
|_com.example.reservations
|_controllers
|_ShopController.java
|_repository
|_ShopRepository.java
|_services
|_ShopService.java
|_ReservationsApplication.java
Turns out I had to have a config file for couchbase repository. What I did was follow the following link and now it all compiles fine!
The problem could be #Autowired in ShopService
#Service
public class ShopService {
#Autowired
private ShopRepository shopRepository;
public ShopService(ShopRepository shopRepository){
this.shopRepository = shopRepository;
}
public Shop getShopBasedOnId(String id) {
return shopRepository.findByShopId(id);
}
}`
should be
#Service
public class ShopService {
private ShopRepository shopRepository;
public ShopService(ShopRepository shopRepository){
this.shopRepository = shopRepository;
}
public Shop getShopBasedOnId(String id) {
return shopRepository.findByShopId(id);
}
}
You can also add #Autowired just above the constructor but it is no longer required if there is only one constructor
In my situation, I had spring boot with multiple modules. So I had to the below to make it work.
#SpringBootApplication (scanBasePackages={"com.sample.test"})
#EnableJdbcRepositories(basePackages={"com.sample.test"})
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
I have the following problem. I trying to start a Spring Boot application with the DB2 database with Hybernate. So i created a repository and used the #Autowired annotation to get some data from the DB. The problem is that when I run the application i receive the following error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field studenteRepository in com.ibm.snam.ai4legal.controller.HelloWorldController required a bean of type 'com.ibm.snam.ai4legal.repositories.StudenteRepository' that could not be found.
Action:
Consider defining a bean of type 'com.ibm.snam.ai4legal.repositories.StudenteRepository' in your configuration.
Here are the classes of the application
Application class:
package com.ibm.snam.ai4legal.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication(scanBasePackages = {"com.ibm"})
public class SBApplication {
public static void main(String[] args) {
SpringApplication.run(SBApplication.class, args);
}
}
Repository class:
package com.ibm.snam.ai4legal.repositories;
import org.springframework.data.repository.CrudRepository;
import com.ibm.snam.ai4legal.model.Studente;
public interface StudenteRepository extends CrudRepository<Studente, Integer>{
}
Model class:
package com.ibm.snam.ai4legal.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
#Entity
public class Studente{
#Id
#GeneratedValue
private int id;
private String nome;
private String cognome;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getnome() {
return nome;
}
public void setnome(String nome) {
this.nome = nome;
}
public String getcognome() {
return cognome;
}
public void setcognome(String cognome) {
this.cognome = cognome;
}
}
Controller class:
package com.ibm.snam.ai4legal.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.ibm.snam.ai4legal.repositories.StudenteRepository;
#RestController
public class HelloWorldController {
#Autowired
StudenteRepository studenteRepository;
#GetMapping(value = "/home")
public ModelAndView helloworld() {
ModelAndView hello = new ModelAndView("helloworld");
return hello;
}
}
and here the pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>projects</groupId>
<artifactId>springwebapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>4.26.14</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
</dependencies>
<!-- <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>-->
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
</project>
On the internet I found that I should insert <context:annotation-config/> in some configuration file but I have no idea in which file I have to put it. Someone can help?
You have to use #ComponentScan annotation. Try the below code.
#ComponentScan({"com.ibm.*"})
#SpringBootApplication
public class SBApplication {
public static void main(String[] args) {
SpringApplication.run(SBApplication.class, args);
}
}
Also mention #Repository annotation in StudenteRepository class.
Either move SBApplication to com.ibm.snam.ai4legal package so it can benefit from default component scanning or add the following annotations to specify packages to be scanned for entities and repositories.
#SpringBootApplication(scanBasePackages = {"com.ibm"})
#EnableJpaRepositories(basePackages = {"com.ibm"})
#EntityScan(basePackages = {"com.ibm"})
public class SBApplication {
public static void main(String[] args) {
SpringApplication.run(SBApplication.class, args);
}
}
Since you are using spring-boot-starter-data-jpa you need to provide the annotation #EnableJpaRepositories to tell springboot to autoconfigure everything.So you might want to use the auto configuration feature of springboot.The #EnableJpaRepositories annotation is not mandatory for auto configuring the spring-data-jpa but in some cases if spring component scan didn't recognize spring-data-jpa in classpath you will have to use this annotation to tell spring to autoconfigure it.
#EnableJpaRepositories will enabling auto configuration support for Spring Data JPA required to know the path of the JPA the repositories. By default, it will scan only the main application package and its sub packages for detecting the JPA repositories.So take care to put the main application class at the root package of your application.
#EnableJpaRepositories(basePackages ="com.ibm")
#SpringBootApplication(scanBasePackages = {"com.ibm"})
public class SBApplication {
public static void main(String[] args) {
SpringApplication.run(SBApplication.class, args);
}
}
Also, if your entity classes are not in the same package then you can use the #EntityScan annotation to specify the base packages. In your case you have not specifies the #Repository annotation on your interface which will tell spring-boot to create default implementations for your interface.If that annotation is not provided then spring will just ignore the interface and the bean creation will not happen.You won't be able to autowire it .So provide that and have methods declared in your interface and spring-bot will take care of the rest.
#Repository
public interface StudenteRepository extends CrudRepository<Studente, Integer>{
//If to find a student record by the id attribute
public Studente findById();
}
I have one framework using Spring Boot which contains a controller RestController class ,
#RequestMapping("/details")
#RestController
public class DataController {
private KafkaStreams kafkaStreams;
public DataController(KafkaStreams kafkaStreams) {
this.kafkaStreams = kafkaStreams;
}
#Autowired
DataService dataService;
#RequestMapping(value = "getAllDetails", method = RequestMethod.GET)
public boolean getAllDetails(KafkaStreams kafkaStreams) {
return ktableService.getAllDetails(kafkaStreams);
}
}
In my service implementation class I am using this kafkaStreams object to find the details for my different services.
Now I am using this framework as a dependency in my one of the other application where I have a runner class,
import org.apache.kafka.streams.KafkaStreams;
#Component
public class PipelineRunner {
private final StreamsBuilder streamsBuilder;
private final KafkaProperties kafkaProperties;
private final SerdesExt serdesExt;
#Autowired
public PipelineRunner(StreamsBuilder streamsBuilder, KafkaProperties kafkaProperties, SerdesExt serdesExt) {
this.streamsBuilder = streamsBuilder;
this.kafkaProperties = kafkaProperties;
this.serdesExt = serdesExt;
}
#PostConstruct
public void run() {
ReflectData.AllowNull.get().addStringable(Utf8.class);
ReflectData.get().addStringable(Utf8.class);
DataProcessor processor = new DataProcessor(streamsBuilder, kafkaProperties,
serdesExt);
start();
}
private void start() {
KafkaStreams kafkaStreams = new KafkaStreams(streamsBuilder.build(),
kafkaProperties.getKafkaStreamsProperties(serdesExt));
System.out.println("----Its is started----");
DataController controller = new DataController(kafkaStreams);
kafkaStreams.start();
}
}
In this class i am trying to create the object for DataController .
So when I am trying to run the application class,
#SpringBootApplication(scanBasePackages = { "framework package" })
#EnableConfigurationProperties(KafkaProperties.class)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I am getting this error,
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in frameworkpackage.controllers.DataController required a bean of type 'org.apache.kafka.streams.KafkaStreams' that could not be found.
Action:
Consider defining a bean of type 'org.apache.kafka.streams.KafkaStreams' in your configuration.
I am new to Spring Boot. So I might be doing something wrong here. If more info is needed I can provide.
UPDATE
My pom file,
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<properties>
<confluent.version>4.1.0</confluent.version>
<kafka.version>1.1.0</kafka.version>
<lombok.version>1.18.0</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>${confluent.version}</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-streams-avro-serde</artifactId>
<version>${confluent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>${kafka.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>${kafka.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-avro</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
A problem is that you are trying to use a bean kafkaStreams in your class DataController, but there is no bean with this name in Spring context. You need to create it manually, so you can autowire it later.
In your case I would suggest to update PipelineRunner.java like this:
import javax.annotation.PostConstruct;
import org.apache.kafka.streams.KafkaStreams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
#Component
public class PipelineRunner
{
private final StreamsBuilder streamsBuilder;
private final KafkaProperties kafkaProperties;
private final SerdesExt serdesExt;
#Autowired
public PipelineRunner(StreamsBuilder streamsBuilder, KafkaProperties kafkaProperties, SerdesExt serdesExt)
{
this.streamsBuilder = streamsBuilder;
this.kafkaProperties = kafkaProperties;
this.serdesExt = serdesExt;
}
#PostConstruct
public void run()
{
ReflectData.AllowNull.get().addStringable(Utf8.class);
ReflectData.get().addStringable(Utf8.class);
DataProcessor processor = new DataProcessor(streamsBuilder, kafkaProperties,
serdesExt);
start();
}
#Bean
KafkaStreams kafkaStreams()
{
KafkaStreams kafkaStreams = new KafkaStreams(
streamsBuilder.build(),
kafkaProperties.getKafkaStreamsProperties(serdesExt));
System.out.println("----Its is started----");
kafkaStreams.start();
return kafkaStreams;
}
}
You dont need to create an instance of DataController by yourself, this will be done automatically by Spring.
More information about Spring approach to beans is available there
I downgrade my application from spring 4.x to 3.x and now when I fire simple test in spock which using autowired bean, this bean is null.
#ContextConfiguration(classes = Configuration.class)
class SomeTestClass extends Specification {
#Autowired
SomeService someService
def "someService"(){
expect:
someService.returnHelloWorld() == "Hello World" // (<- NullPointer)
}
}
My pom.xml file:
<dependencies>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.12</version>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.1-groovy-2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>1.1-groovy-2.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
After when I downgrade also spock-core/spring to 0.6-groovy-1.8 and groovy-all to 1.8 and fire my test it throws this exception:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'someAnotherBean' defined in file
../SomeBean.class: Instantiation of bean failed; nested exception
isorg.springframework.beans.BeanInstantiationException: Could
notinstantiate bean class [..SomeBean.class]: No default
constructorfound; nested exception is
java.lang.NoSuchMethodException:..SomeBean.()
This bean contains contructor which i used to intizialize final fieds in class:
#Component
#PropertySource("classpath:someproperties.properties")
public class HeaderFactory {
private final SomeObject someObject;
public HeaderFactory(#Value("${someProperty1}") String someProperty1, #Value("${someProperty2}") String someProperty2) {
SomeObject someObject = new SomeObject(someProperty1,someProperty2);
this.someObject = someObject;
}
}
Everything worked pretty well before I dowgraded spring version. Any ideas?
You could create a configuration class and define the problematic beans there:
#Configuration
class MyConfig {
#Value("${someProperty1}") String prop1;
#Value("${someProperty2}") String prop2
#Bean
public SomeBean someBean() {
SomeBean bean = new SomeBean(prop1, prop2);
return bean;
}
}
Documentation here: https://docs.spring.io/spring/docs/3.2.0.RELEASE/spring-framework-reference/html/new-in-3.0.html#new-feature-java-config
I resolved my issue by this way:
#Component
public class UrlBuilder {
private final String host;
private final String port;
private final String protocol;
#Autowired
public UrlBuilder(Environment env) {
this.protocol = env.getRequiredProperty("app.server.protocol").toLowercase();
this.serverHost = env.getRequiredProperty("app.server.host");
this.serverPort = env.getRequiredProperty("app.server.port", Integer.class);
}
}
Source
We want to implement a REST-Service on a Jetty, that receives a Heartbeat from multiple Clients and these Heartbeats are stored in a Hashmap to work with them in further functionallities.
Thats how the code looks like at the moment:
The class that should be injected.
public class SharedMemory {
private SharedMemory sharedMemory = null;
private HashMap<String, HeartbeatModel> memory = null;
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private final Lock readLock = lock.readLock();
private final Lock writeLock = lock.writeLock();
public SharedMemory(){
memory = new HashMap<String, HeartbeatModel>();
}
...
}
The binder class:
public class SharedMemoryBinder extends AbstractBinder{
#Override
protected void configure() {
bind(new SharedMemory()).to(SharedMemory.class);
}
}
The feature class:
public class SharedMemoryFeature implements Feature{
#Override
public boolean configure(FeatureContext context) {
context.register(new SharedMemoryBinder());
return true;
}
}
The service class
#Path("/HeartbeatService")
public class GCEHeartbeatService {
#Inject
private SharedMemory sharedMemory;
#POST
#Path("/postHeartbeat")
#Consumes(MediaType.APPLICATION_JSON)
public Response postHeartbeat(Heartbeat heartbeat){
sharedMemory.storeToMemory(heartbeat);
return Response.ok().build();
}
...
}
The application class:
#ApplicationPath("/")
public class Application extends javax.ws.rs.core.Application {
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(GCEHeartbeatService.class);
classes.add(SharedMemoryFeature.class);
return classes;
}
}
These are the used dependencies:
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>de.hszg</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>2.13</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.3</version>
</dependency>
</dependencies>
So with this configuration, i always get a 415 unsupported media type exception when i post a heartbeat to the postHeartbeat service, even with another media type.
"...i always get a 415 unsupported media type exception when i post"
This doesn't seem like a problem related to your DI configuration. It looks like you just need to register the JSON provider. With this particular provider
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.3</version>
</dependency>
If you override the registration of resources/provider through classpath scanning (which you have done, simply by overriding getClasses() and returning a non-empty set, then the provider will not be registered.
You can simply register it yourself.
classes.add(JacksonJsonProvider.class);
-- or --
classes.add(JacksonJaxbJsonProvider.class);
If you look in the jar, you will also see an ExceptionMapper you may want to register.
Alternatively, you can use this dependency
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.17</version>
</dependency>
which wraps the above dependency in a auto-discoverable feature, and registers, the provider and the ExceptionMapper. With this dependency, you won't need to register anything. If for some weird reason it isn't register, you can just add it yourself
classes.add(JacksonFeature.class);
As an aside, if portability is not an issue, I would use the ResourceConfig class (which extends Application) instead. It's much easier to work with.
#ApplicationPath("/")
public class AppConfig extends ResourceConfig {
public AppConfig() {
packages("scan.packages.for.resource.and.provider");
register(ResourceOrProvider.class);
register(new MyAppBinder());
}
}
See the ResourceConfig API