Код: Выделить всё
@Mapper
@Component
public interface PriceEntityMapper {
@Mapping(source="brandId", target="brandId")
@Mapping(source="startDate", target="startDate", qualifiedByName = "timestampToLocalDateTime")
@Mapping(source="endDate", target="endDate", qualifiedByName = "timestampToLocalDateTime")
@Mapping(source="priceList", target="priceList")
@Mapping(source="productId", target="productId")
@Mapping(source="priority", target="priority")
@Mapping(source="price", target="price")
@Mapping(source="curr", target="currency")
Price priceEntityToPrice(PriceEntity priceEntity);
@Named("timestampToLocalDateTime")
default LocalDateTime timestampToLocalDateTime(Timestamp timestamp) {
return timestamp.toLocalDateTime();
}
}
Код: Выделить всё
@Service
public class PriceServiceImpl implements PriceService {
private final PriceRepository priceRepository;
private final PriceEntityMapper priceEntityMapper;
@Autowired
public PriceServiceImpl(PriceRepository priceRepository, PriceEntityMapper priceEntityMapper) {
this.priceRepository = priceRepository;
this.priceEntityMapper = priceEntityMapper;
}
@Override
public Price getPrice(LocalDateTime applicationDate, Integer productId, Integer brandId) {
try {
//PriceEntity priceEntity = priceRepository.findByBrandIdAndProductIdAndStartDateLessThanEqualApplicationDateAndEndDateGreaterThanEqualApplicationDate(brandId, productId, Timestamp.valueOf(applicationDate));
return priceEntityMapper.priceEntityToPrice(new PriceEntity());
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Price not found", e);
}
}
}
Параметр 1 конструктора в com.dharian.application.service.PriceServiceImpl потребовался bean-компонент типа com.dharian.infraestructure.mapper.PriceEntityMapper, который не удалось найти.
Но у меня есть аннотации @Mapper и @Component, а также
Код: Выделить всё
@SpringBootApplication
@ComponentScan({"com.dharian.infraestructure", "com.dharian.application"})
public class PruebatecnicaApplication {
public static void main(String[] args) {
SpringApplication.run(PruebatecnicaApplication.class, args);
}
}
что это может быть?
Я попробовал @ComponentScan, изменил автоподключение и изменил аннотацию через Mapper класс.
Подробнее здесь: https://stackoverflow.com/questions/784 ... und-a-bean
Мобильная версия