In a SpringBoot application, I would like to do some test about the repository layer.
@RunWith(SpringRunner.class)
@DataJpaTest
public class VisitRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private VisitRepository visitRepository;
...
}
When I try to run test from VisitRepositoryTest
, I get an error about DefaultConfigService
Field defaultConfigService in com.norc.Application required a bean of type 'com.norc.service.DefaultConfigService' that could not be found.
So this needs to run the Application
?
I tried to put a bean of DefaultConfigService
in VisitRepositoryTest
, but it's not allowed.
This class is used in my app
@EntityScan(basePackageClasses = {Application.class, Jsr310JpaConverters.class})
@SpringBootApplication
@EnableScheduling
public class Application implements SchedulingConfigurer {
@Autowired
private DefaultConfigService defaultConfigService;
...
}
How to manage that?
Edit
In my Application, I use this class in a cron tab:
@Service
public class DefaultConfigServiceImpl implements DefaultConfigService {
private final DefaultConfigRepository defaultConfigRepository;
@Autowired
public DefaultConfigServiceImpl(final DefaultConfigRepository defaultConfigRepository) {
this.defaultConfigRepository = defaultConfigRepository;
}
}