I have next mapper:
@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();
}
}
and next impl:
@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);
}
}
}
well when im trying to run app give me the next error:
Parameter 1 of constructor in com.dharian.application.service.PriceServiceImpl required a bean of type ‘com.dharian.infraestructure.mapper.PriceEntityMapper’ that could not be found.
But i have the annotation @Mapper and @Component, also i have
@SpringBootApplication
@ComponentScan({"com.dharian.infraestructure","com.dharian.application"})
public class PruebatecnicaApplication {
public static void main(String[] args) {
SpringApplication.run(PruebatecnicaApplication.class, args);
}
}
for scan the package but doesnt work.
what can be?
I tried @ComponentScan, change autowired, and change annotation over Mapper class
Dharian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.