我有一个弹簧启动弹簧数据应用程序。当我的存储库扩展CrudRepository时,这工作正常。为了获得动态查询,我扩展了QueryByExampleExecutor。在扩展QueryByExampleExecutor并运行mvn spring-boot:run之后,我收到以下错误:
***An exception occured while running. null: InvocationTargetException: Error creating bean with name 'dataSourceInitializerPostProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.beans.factory.BeanFactory org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.beanFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeProfileRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)***
存储库类:
@Transactional
@Repository
public interface EmployeeProfileRepository extends CrudRepository<EmployeeProfile, Long>, QueryByExampleExecutor<EmployeeProfile> {
}
服务类:
@Service
public class EmployeeProfileService {
@Autowired
private EmployeeProfileRepository empProfileRepository;
public List<EmployeeProfile> searchEmployees(Long id, String firstName, String lastName) {
List<EmployeeProfile> employees = new ArrayList<>();
EmployeeProfile emp = new EmployeeProfile();
emp.setId(id);
emp.setFirstName(firstName);
emp.setLastName(lastName);
Example<EmployeeProfile> example = Example.of(emp);
Iterable<EmployeeProfile> iterable = empProfileRepository.findAll(example);
iterable.forEach(employees::add);
return employees;
}
}
申请类:
@Configuration
@EnableAutoConfiguration
@EnableJpaRepositories("com.employee.dao")
@ComponentScan("com.employee")
@EntityScan("com.employee.dto")
public class Application extends SpringBootServletInitializer {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}