2016-06-19 3 views
0

My Spring Boot 애플리케이션은 Spring Security OAuth2에 의해 보안됩니다. 사용자 데이터는 SQL 데이터베이스에 저장됩니다. 나는 여기서 royclarkson의 Oauth 보호 REST 서비스를 따랐다. 이 프로젝트는 Spring Data JPA와 함께 작동합니다. 이것은 잘 작동합니다.Neo4J JDBC 및 MySQL을 이용한 스프링 부트

https://github.com/royclarkson/spring-rest-service-oauth

는하지만 지금은 Neo4J - JDBC (JDBC 템플릿)을 통해 내 Neo4J - 데이터베이스에서 데이터를 얻기 위해 내 Neo4J 구성을 구현하고자합니다. 여기에 나는이 GitHub의 프로젝트 다음 :

https://github.com/neo4j-examples/movies-java-spring-boot-jdbc

작동 독립 실행 형 응용 프로그램으로,하지만 내가 togehter이 두 개의 프로젝트를 넣어 경우,이 예외 얻을 :

HibernateJpaAutoConfiguration.class]: Invocation of init method failed; 
nested exception is org.hibernate.HibernateException: 
Unable to determine Dialect to use [name=Neo4j, majorVersion=3]; 
user must register resolver or explicitly set 'hibernate.dialect' 

내 Neo4jConfig.java의 모습을 이 :

@Configuration 
public class Neo4jConfig { 

//NEO4J Server Implementation via JDBC 

private static final String NEO4J_URL = System.getProperty("NEO4J_URL","jdbc:neo4j://localhost:7474"); 
private static final String NEO4J_USER = System.getProperty("NEO4J_USER","neo4j"); 
private static final String NEO4J_PASSWORD = System.getProperty("NEO4J_PASSWORD","neo4j"); 

@Bean 
public DataSource dataSource() { 
    return new DriverManagerDataSource(NEO4J_URL, NEO4J_USER, NEO4J_PASSWORD); 
} 

public Neo4jConfig(){ 

} 

public String getNeo4JURL(){ 
    return NEO4J_URL; 
} 
} 

TripController.java

import hello.data.Trip; 

@RestController 
public class TripController { 

@Autowired 
JdbcTemplate template; 

public static final RowMapper<Trip> TRIP_ROW_MAPPER = new RowMapper<Trip>() { 
    public Trip mapRow(ResultSet rs, int rowNum) throws SQLException { 
     return new Trip(rs.getString("tripname"),rs.getInt("slots"), rs.getInt("to_date"), rs.getInt("from_date")); 
    } 
}; 

String SEARCH_TRIPS_QUERY = 
     " MATCH (t:Trip)\n" + 
     " RETURN t.tripname as tripname, t.slots as slots, t.to_date as to_date, t.from_date as from_date"; 

@RequestMapping(path = "/alltrips", method = RequestMethod.GET) 
public List<Trip> alltrips() { 

    return template.query(SEARCH_TRIPS_QUERY, TRIP_ROW_MAPPER); 
} 

} 

나는 너희들이 내 질문을 이해하기를 바랍니다. 나는 봄에 정말로 새로운 사람이다. 나는 누구나 나를 도울 수 있기를 바란다 :

+0

"두 프로젝트를 함께 넣으십시오"라는 것은 무엇을 의미합니까? 일할 때나하지 않을 때 더 잘 설명 할 수 있습니까? – visola

답변

0

이것은 Neo4j가 RDBMS 데이터베이스가 아니며 방언이 기본적으로 제공되지 않기 때문에 hibernate가 Neo4J에 대한 어떤 방언도 찾지 않기 때문에 발생한다. 당신은 당신이 RDBMS를 사용하지 않을 아예 경우 최대 절전 모드 제거, 최대 절전 모드 OGM는 (검색 pom.xml 파일에 포함)를 사용하고 EntityManager를 구성하는 구성 및 트랜잭션 매니저

@Configuration 
@EnableJpaRepositories(basePackages = { 
     "your repository packages" }, entityManagerFactoryRef = "n4jEntityManager", transactionManagerRef = "n4jTxnManager") 
public class DatabaseConfiguration { 


    @Bean(name = "n4jEntityManager") 
    public LocalContainerEntityManagerFactoryBean entityManager() { 

     Map<String, Object> properties = new HashMap<String, Object>(); 
     properties.put("javax.persistence.transactionType", "resource_local"); 
     properties.put("hibernate.ogm.datastore.provider","neo4j"); 
     properties.put("hibernate.ogm.datastore.host","localhost"); 
     properties.put("hibernate.ogm.datastore.port","7474"); 
     properties.put("hibernate.ogm.datastore.database", "your database"); 
     properties.put("hibernate.ogm.datastore.create_database", "true or false"); 

     LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean(); 
     entityManager.setPackagesToScan("your domain packages"); 
     entityManager.setPersistenceUnitName("n4jPU"); 
     entityManager.setJpaPropertyMap(properties); 
     entityManager.setPersistenceProviderClass(HibernateOgmPersistence.class); 
     return entityManager; 
    } 

    @Bean(name = "n4jTxnManager") 
    public PlatformTransactionManager txnManager() { 
     JpaTransactionManager transactionManager = new JpaTransactionManager(); 
     transactionManager.setEntityManagerFactory(mongoEntityManager().getObject()); 
     return transactionManager; 
    } 

} 

다음을 사용하지만 제안 할 수 있습니다 Neo4j 만 사용하게됩니다. Spring 데이터는 NoSQL 데이터베이스를 잘 지원하며 엔티티는 @NodeEntity 및 @GraphId와 같은 주석을 사용하여 정의 할 수 있습니다.

+0

답변 해 주셔서 감사합니다. 말씀 드렸듯이 스프링 데이터를 사용하기 시작합니다. – Chris