我的Spring Boot應用程序受Spring Security OAuth2的保護。用戶數據存儲在SQL數據庫中。我跟着royclarkson的Oauth保護REST服務。該項目與Spring Data JPA一起工作。這工作正常。Spring使用Neo4J JDBC和MySQL啓動
https://github.com/royclarkson/spring-rest-service-oauth
但現在我想實現我的Neo4j配置通過的Neo4j-JDBC(JDBC模板),以獲得從我的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);
}
}
我希望你們能理解我的問題。我知道,我是Spring的新手,但我希望任何人都可以幫助我:)
當你說:「把這兩個項目放在一起」時,你是什麼意思?你能不能更好地闡述他們在什麼時候工作,什麼時候不工作? – visola