我创建了一个Spring Boot应用程序,并使用要执行的方法创建了一个类。将项目部署为war文件时,出现错误:
- ParseUpcomingMatchesFile需要找不到名为'entityManagerFactory'的bean。考虑在配置中定义一个名为“ entityManagerFactory”的bean。
- 创建名称为“ parseUpcomingMatchesFile”的bean时出错:通过字段“ matchesRepository”表示的不满意的依赖关系;
- 创建名称为'matchesRepository'的bean时出错:设置bean属性'entityManager'时无法创建类型为[org.springframework.orm.jpa.SharedEntityManagerCreator]的内部bean'(内部bean)#2875c2a3';
我将显示代码的某些部分:
@Configuration
@EnableAsync
@EnableScheduling
@ComponentScan(basePackages={"parser","service","processing","automation"})
public class TennisExecutor extends SpringBootServletInitializer {
@Autowired
public ParseUpcomingMatchesFile parseUpcomingMatchesFile;
@Autowired
public ParseFinishedMatchesFile parseFinishedMatchesFile;
@Autowired
public PlayersProcessor playersProcessor;
public TennisExecutor() {}
@Scheduled(cron = "0 */2 * * * ?")
public void executetasks() throws IOException {
parseUpcomingMatchesFile.parseMatchesFile(webDriver,new File(ConstantData.TOMORROW_UPCOMING_MATCHES_FILE_PATH));
}
@Component
@EnableJpaRepositories(basePackageclasses={MatchesRepository.class,PlayersRepository.class})
@EntityScan(basePackageclasses={MatchesEntity.class,PlayersEntity.class})
public class ParseUpcomingMatchesFile {
@Autowired
public MatchesRepository matchesRepository;
@Autowired
public PlayersRepository playersRepository;
static final org.apache.log4j.Logger logger = Logger.getLogger(ParseUpcomingMatchesFile.class);
public ParseUpcomingMatchesFile() {
}
public void parseMatchesFile(WebDriver webDriver,File file) throws IOException {
String fullNameone = "player1";
String fullNameTwo = "player2";
int matchId = matchesRepository.selectIdByPlayerNames(fullNameone,fullNameTwo);
}
}
@Repository
public interface MatchesRepository extends CrudRepository<MatchesEntity,Integer> {
@Query(value = "select m from MatchesEntity m")
List<MatchesEntity> selectAllMatches();
@Query(value = "select m.id from MatchesEntity m where m.namePlayer1 = :namePlayer1 and " +
"m.namePlayer2 = :namePlayer2")
int selectIdByPlayerNames(String namePlayer1,String namePlayer2);
}
我试图删除.m2 / repository文件夹,添加了spring-data-jpa的依赖项,但没有任何变化。 有人有什么建议吗?