2017-02-12 3 views
0

봄 부팅 + 최대 절전 모드 5 응용 프로그램에서 java.lang.IllegalArgumentException: Property 'sessionFactory' is required 받기. 나는이SessionFactory 예외

@Autowired 
    public void setupSessionFactory(SessionFactory sessionFactory) { 
     setSessionFactory(sessionFactory); 
     getHibernateTemplate().setCheckWriteOperations(false); 
    } 

처럼 autowire하기 위해 노력 또한 내가 어떻게 내 설정 파일

@Bean 
    public HibernateJpaSessionFactoryBean getSessionFactory() { 
     return new HibernateJpaSessionFactoryBean(); 
    } 

    @Bean 
    public SessionFactory sessionFactory(){ 
     return new LocalSessionFactoryBean().getObject(); 
    } 

    @Bean 
    public HibernateTransactionManager transactionManager(SessionFactory sf) { 
     return new HibernateTransactionManager(sf); 
    } 

내 application.yml 파일

spring: 
    datasource: 
    url: jdbc:postgresql://localhost:5432/db 
    driver-class-name: org.postgresql.Driver 
    username: postgres 
    password: password 
    jpa: 
    hibernate: 
     ddl-auto: update 

security: 
    basic: 
    enabled: false 

어떤 아이디어에 같은 물건을 추가하려고 이거 해결해?

답변

0

return new LocalSessionFactoryBean().getObject();이 null을 반환 할 수 있습니다. null의 경우도 기본이다

public SessionFactory getObject() { 
     return this.sessionFactory; 
} 

:

이 방법은 단순히 내부의 필드 값을 반환합니다.

세션 팩터 리를 구성해야합니다. 데이터 소스를 설정하고, 스캔 할 패키지를 만들고, 최대 절전 모드 속성을 설정해야합니다. Something like that : 설명 :

@Bean 
    public LocalSessionFactoryBean sessionFactory() { 
     LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); 
     sessionFactory.setDataSource(restDataSource()); 
     sessionFactory.setPackagesToScan(
     new String[] { "org.baeldung.spring.persistence.model" }); 
     sessionFactory.setHibernateProperties(hibernateProperties()); 

     return sessionFactory; 
    } 
+0

오류로 변경 com.jgang.realestate.service.OwnerServiceImpl에 필드 ownerRepository를 찾을 수 없습니다 '의 EntityManagerFactory'라는 이름의 빈을 요구했다. 작업 : 구성에서 'entityManagerFactory'라는 bean 정의를 고려하십시오. – MolecularMan

+0

'com.jgang.realestate.service.OwnerServiceImpl'은 무엇인지 전혀 알지 못하지만 질문의 문제는 해결되지만 – Andremoniy

+0

과 btw, 나는 datasource 및 hibernate 속성을 설정하기 위해 application.yml을 사용할 수 있습니까? – MolecularMan