복붙노트

[SQL] 봄 부팅 - 저장소 필드를 찾을 수 없습니다 '의 EntityManagerFactory'라는 이름의 빈을 요구

SQL

봄 부팅 - 저장소 필드를 찾을 수 없습니다 '의 EntityManagerFactory'라는 이름의 빈을 요구

나는 봄 부팅 응용 프로그램을 개발하는 과정에서 오전 서버를 시작할 때이 오류를 가로 질러왔다. 내가 잘못 어떤 주석을 정의하거나 종속성을 놓치고 있는지 확실하지 않다. 어떤 도움을 주시면 감사하겠습니다.

Main 클래스 :

@SpringBootApplication
public class FantasyManagerApplication {

    public static void main(String[] args) {
        SpringApplication.run(FantasyManagerApplication.class, args);
    }
}

LeagueService.java:

@Service
public class LeagueService {

    @Autowired
    private LeagueRepository leagueRepository;
    @Autowired
    private PlayerRepository playerRepository;
    @Autowired
    private TeamRepository teamRepository;

    /**
     * Returns a list of all the leagues in the database 
     * @return List<League>
     */
    public List<League> getAllLeagues(){
        List<League> leagues = new ArrayList<>();
        leagueRepository.findAll()
        .forEach(leagues::add);
        return leagues;
    }

    /**
     * Find details for a particular League
     * @param leagueId
     * @return League
     */
    public League getLeagueById(long leagueId){
        return leagueRepository.findOne(leagueId);
    }

    /**
     * Find the leagueSettings for a particular League  
     * @param leagueId
     * @return LeagueSettings
     */
    public LeagueSettings getLeagueSettingsById(long leagueId){
        return leagueRepository.findOne(leagueId).getLeagueSettings();
    }


    /**
     * Returns a list of all the Team's in the League
     * @param leagueId
     * @return List<Team>
     */
    public List<Team> getTeamsInLeague(long leagueId){
        List<Team> teams = new ArrayList<>();
        leagueRepository.findOne(leagueId).getTeams()
        .forEach(teams::add);
        return teams;

    }

    /**
     * Returns a list of all the Player's in the League
     * @param leagueId
     * @return List<Player>
     */
    public List<Player> getPlayersInLeague(long leagueId){
        List<Player> players = new ArrayList<>();
        leagueRepository.findOne(leagueId).getPlayers()
        .forEach(players::add);
        return players;     
    }

    /**
     * Returns a list of all the User's in the League
     * @param leagueId
     * @return List<User>
     */
    public List<User> getUsersInLeague(long leagueId){
        List<User> users = new ArrayList<>();
        leagueRepository.findOne(leagueId).getUsers()
        .forEach(users::add);
        return users;       
    }


    /**
     * Add League to database
     * @param league
     */
    public void addLeague(League league){
        leagueRepository.save(league);
    }

    /**
     * Assign LeagueSettings for a League
     * @param userId
     * @param leagueSettings
     */
    public void assignLeagueSettings(long leagueId, LeagueSettings leagueSettings){
        League league = leagueRepository.findOne(leagueId);
        league.setLeagueSettings(leagueSettings);
        leagueRepository.save(league);  
    }

    /**
     * Assign a Player to a League and vice versa
     * @param leagueId
     * @param playerId
     */
    public void assignPlayerToLeague(long leagueId, long playerId){
        //Find the league and player from the database
        League league = leagueRepository.findOne(leagueId);
        Player player = playerRepository.findOne(playerId);

        //Get the players that the league already has
        List<Player> players = new ArrayList<>();
        players = league.getPlayers();

        //Get the leagues that the player is part of
        List<League> leagues = new ArrayList<>();
        leagues = player.getLeagues();

        //Assign player to this league and vice versa
        leagues.add(league);
        players.add(player);
        league.setPlayers(players);
        player.setLeagues(leagues);

        //Update changes in database
        playerRepository.save(player);
        leagueRepository.save(league);
    }

    /**
     * Assign a Team to a League and vice versa
     * @param leagueId
     * @param teamId
     */
    public void assignTeamToLeague(long leagueId, long teamId){
        //Find the league and player from the database
        League league = leagueRepository.findOne(leagueId);
        Team team = teamRepository.findOne(teamId);

        //Get the teams that are already in the league
        List<Team> teams = new ArrayList<>();
        teams = league.getTeams();

        //Assign team to this league and vice versa
        teams.add(team);
        league.setTeams(teams);
        team.setLeague(league);

        //Update changes in database
        teamRepository.save(team);
        leagueRepository.save(league);
    }


    /**
     * Edit the details for a particular League
     * @param league
     */
    public void updateLeague(League league, long leagueId){
        leagueRepository.save(league);
    }


    /**
     * Delete the League from the database
     * @param leagueId
     */
    public void deleteLeague(long leagueId){
        leagueRepository.delete(leagueId);
    }

}

LeagueRepository.java

public interface LeagueRepository extends CrudRepository<League, Long> {

}

pom.hml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dheeraj</groupId>
    <artifactId>fantasy-manager</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>fantasy-manager</name>
    <description>Fantasy Manager Application</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.2.3.Final</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

오류:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field leagueRepository in com.dheeraj.service.LeagueService required a bean named 'entityManagerFactory' that could not be found.


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

해결법

  1. ==============================

    1.스프링 부팅 스타터 데이터 JPA는 당신이 필요로하는 모든 절전 종속성에서 가져옵니다. 5.0.11 및 최대 절전 모드-의 EntityManager : 봄 부트 버전 1.5.1를 사용하면, 최대 절전 모드 코어에 끌어 5.0.11을. 불필요 할뿐만 아니라, 귀하의 최대 절전 모드 의존성 버전은 오류의 원인이 무엇인지 내가 추측하고있어 어느 일치하지 않습니다.

    스프링 부팅 스타터 데이터 JPA는 당신이 필요로하는 모든 절전 종속성에서 가져옵니다. 5.0.11 및 최대 절전 모드-의 EntityManager : 봄 부트 버전 1.5.1를 사용하면, 최대 절전 모드 코어에 끌어 5.0.11을. 불필요 할뿐만 아니라, 귀하의 최대 절전 모드 의존성 버전은 오류의 원인이 무엇인지 내가 추측하고있어 어느 일치하지 않습니다.

    당신의 pom.xml에서 이러한 종속성을 제거하십시오.

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.3.Final</version>
    </dependency>
    
  2. ==============================

    2.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>   
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.3.Final</version>
    </dependency>
    
  3. ==============================

    3.최대 절전 모드 코어 5.2.0 스프링 데이터 JPA 동안 프로세스 컬렉션 문제가 있습니다. 당신이 스프링 데이터 JPA를 사용할 때 위의 최대 절전 모드 코어 5.2.1 및 스프링 데이터 JPA로 괜찮습니다.

    최대 절전 모드 코어 5.2.0 스프링 데이터 JPA 동안 프로세스 컬렉션 문제가 있습니다. 당신이 스프링 데이터 JPA를 사용할 때 위의 최대 절전 모드 코어 5.2.1 및 스프링 데이터 JPA로 괜찮습니다.

    이후 5.2.0 최대 절전 모드에서. 최대 절전 모드-의 EntityManager는 더 이상 필요하지 않습니다.

    그래서 변화를 시도 :

    <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-core</artifactId>
     <version>4.1.4.Final</version>
    </dependency>
    

    이 버전 :

    <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-core</artifactId>
     <version> 5.2.1.Final</version>
    </dependency>
    

    이것은 나를 위해 그것을 해결했습니다.

  4. ==============================

    4.문제는 버전 불일치로 인해 수 있습니다. 문제는 이런 의존성을 지정함으로써 해결 될 수있다 (버전이 언급되어 있지 않기 때문에, 그 자동 관리)

    문제는 버전 불일치로 인해 수 있습니다. 문제는 이런 의존성을 지정함으로써 해결 될 수있다 (버전이 언급되어 있지 않기 때문에, 그 자동 관리)

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    
    
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    
  5. ==============================

    5.에서 종속성을 삭제하십시오

    에서 종속성을 삭제하십시오

    추가 귀하의 IDE의 업데이트를 통해 사용자의 프로젝트 종속성을 업데이트는 기능 종속성, 또는 프로젝트의 폴더에서 설치 MVN 실행하여.

  6. from https://stackoverflow.com/questions/42182426/spring-boot-repository-field-required-a-bean-named-entitymanagerfactory-that by cc-by-sa and MIT license