Spring Boot版本<version>2.2.0.RELEASE</version>
说明:
com.shawn.foodrating.service.impl.AdServiceImpl中的构造函数的参数2需要找不到'java.lang.Integer'类型的bean。
动作:
考虑在您的配置中定义类型为'java.lang.Integer'的bean。
@Service
@Transactional(rollbackOn = Exception.class)
@AllArgsConstructor
public class AdServiceImpl implements AdService {
private AdRepository repository;
private FileService fileService;
@Value("${app.ad.DefaultPageSize}")
private Integer DEFAULT_PageSize;
@Value("${app.ad.ImagePath}")
private String AD_IMAGE_PATH;
@Value("${app.ad.ImageUrl}")
private String AD_IMAGE_URL;
加载属性文件
@SpringBootApplication
@PropertySource("classpath:app.properties")
public class FoodRatingApplication {
public static void main(String[] args) {
SpringApplication.run(FoodRatingApplication.class, args);
}
}
不确定那是什么问题。
您可以按以下方式使用。
@Service
@Configuration
@ComponentScan
@PropertySource("classpath:app.properties")
@Transactional(rollbackOn = Exception.class)
@AllArgsConstructor
public class AdServiceImpl implements AdService {
private AdRepository repository;
private FileService fileService;
@Value("${app.ad.DefaultPageSize}")
private Integer DEFAULT_PageSize;
@Value("${app.ad.ImagePath}")
private String AD_IMAGE_PATH;
@Value("${app.ad.ImageUrl}")
private String AD_IMAGE_URL;
要使用@Value
批注,必须在同一类中使用@Configuration
和@PropertySource
。