I'm trying to inject my service to perform unit tests on some methods.
In my controller I have not had any problem, and in other tests I have been able to inject the repository correctly.
The problem is that I get the following error.
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xxx.xxx.food_production.service.FoodProductionService' available: expected at least 1 bean which qualifies as autowire candidate.
My service layer:
@Service
public class FoodProductionService {
private static final Logger LOGGER = LogManager.getLogger();
private final RecipeGroupRepository recipeGroupRepository;
private final RecipeRepository recipeRepository;
private final RecipeTypeRepository recipeTypeRepository;
private final PhaseCookModeRepository phaseCookModeRepository;
private final PhaseCookTypeRepository phaseCookTypeRepository;
private final PhaseAlarmTypeRepository phaseAlarmTypeRepository;
private final RecipeIngredientRepository recipeIngredientRepository;
private final IngredientUnitRepository ingredientUnitRepository;
private final LanguageRepository languageRepository;
private final RecipeProductFamilyRepository recipeProductFamilyRepository;
private final RecipeCuisineRepository recipeCuisineRepository;
private final RecipeAccesoryRepository recipeAccesoryRepository;
private final RecipeSmartDataRepository recipeSmartDataRepository;
private final RecipeFavouriteRepository recipeFavouriteRepository;
private final StorageService storageService;
@Autowired
public FoodProductionService(RecipeGroupRepository recipeGroupRepository, RecipeRepository recipeRepository, RecipeTypeRepository recipeTypeRepository, PhaseCookModeRepository phaseCookModeRepository, PhaseCookTypeRepository phaseCookTypeRepository, PhaseAlarmTypeRepository phaseAlarmTypeRepository, RecipeIngredientRepository recipeIngredientRepository, IngredientUnitRepository ingredientUnitRepository, LanguageRepository languageRepository, RecipeProductFamilyRepository recipeProductFamilyRepository, RecipeCuisineRepository recipeCuisineRepository, RecipeAccesoryRepository recipeAccesoryRepository, RecipeSmartDataRepository recipeSmartDataRepository, RecipeFavouriteRepository recipeFavouriteRepository, StorageService storageService) {
this.recipeGroupRepository = recipeGroupRepository;
this.recipeRepository = recipeRepository;
this.recipeTypeRepository = recipeTypeRepository;
this.phaseCookModeRepository = phaseCookModeRepository;
this.phaseCookTypeRepository = phaseCookTypeRepository;
this.phaseAlarmTypeRepository = phaseAlarmTypeRepository;
this.recipeIngredientRepository = recipeIngredientRepository;
this.ingredientUnitRepository = ingredientUnitRepository;
this.languageRepository = languageRepository;
this.recipeProductFamilyRepository = recipeProductFamilyRepository;
this.recipeCuisineRepository = recipeCuisineRepository;
this.recipeAccesoryRepository = recipeAccesoryRepository;
this.recipeSmartDataRepository = recipeSmartDataRepository;
this.recipeFavouriteRepository = recipeFavouriteRepository;
this.storageService = storageService;
}
My test configuration:
@SpringBootApplication(scanBasePackages = {"com.xxx.xxx.*"})
public class FoodApplicationTest {
private static final Logger logger = LogManager.getLogger(FoodApplicationTest.class);
public static void main(String[] args) {
SpringApplication.run(FoodApplicationTest.class, args);
logger.info("Test Running!!");
}
}
My test class
@ExtendWith(SpringExtension.class)
@DataJpaTest
@ContextConfiguration(classes = {FoodApplicationTest.class}, loader = AnnotationConfigContextLoader.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@PropertySource(value = "classpath:application-food-test.properties")
public class RecipeParserTest {
//Test to check the correct functionality of the recipe parsees
//Logger
private static final Logger logger = LogManager.getLogger(RecipeParserTest.class);
private static final long USER_ID = 1L;
private final RecipeRepository recipeRepository;
private final RecipeSmartDataRepository recipeSmartDataRepository;
private final FoodProductionService foodProductionService;
@Autowired
public RecipeParserTest(RecipeRepository recipeRepository, RecipeSmartDataRepository recipeSmartDataRepository, FoodProductionService foodProductionService) {
this.recipeRepository = recipeRepository;
this.recipeSmartDataRepository = recipeSmartDataRepository;
this.foodProductionService = foodProductionService;
}
I have seen some questions similar than me but i can´t find any solution.
Both the service and the repository are in the same package.
Aucun commentaire:
Enregistrer un commentaire