├── .gitignore ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main ├── java │ └── com │ │ └── example │ │ ├── DatasourceConfig.java │ │ ├── DemoApplication.java │ │ ├── graph │ │ ├── controller │ │ │ └── GraphPersonController.java │ │ ├── domain │ │ │ └── GraphPerson.java │ │ ├── repository │ │ │ └── GraphPersonRepository.java │ │ └── service │ │ │ ├── GraphPersonService.java │ │ │ └── GraphPersonServiceImpl.java │ │ └── relational │ │ ├── controller │ │ └── PersonController.java │ │ ├── domain │ │ └── Person.java │ │ ├── repository │ │ └── PersonRepository.java │ │ └── service │ │ ├── PersonService.java │ │ └── PersonServiceImpl.java └── resources │ └── application.yml └── test └── java └── com └── example └── DemoApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # neo4j-mysql-spring-boot 2 | Neo4j, MySQL, Spring boot example 3 | 4 | Set up is explained in my medium post found [here](https://medium.com/@devgoth/spring-boot-with-neo4j-mysql-4036a54efd3c) 5 | 6 | Follow me on twitter [@devgoth](https://twitter.com/devgoth) 7 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.4.2.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | maven { url "https://repo.spring.io/snapshot" } 8 | } 9 | dependencies { 10 | classpath "mysql:mysql-connector-java:6.0.4" 11 | classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" 12 | } 13 | } 14 | 15 | apply plugin: 'application' 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'org.springframework.boot' 19 | 20 | jar { 21 | baseName = 'demo' 22 | version = '0.0.1-SNAPSHOT' 23 | } 24 | 25 | sourceCompatibility = 1.8 26 | 27 | repositories { 28 | mavenCentral() 29 | maven { url "https://repo.spring.io/snapshot" } 30 | } 31 | 32 | 33 | dependencies { 34 | compile "mysql:mysql-connector-java:6.0.4" 35 | compile "org.springframework.boot:spring-boot-starter-jdbc" 36 | compile "org.springframework.boot:spring-boot-starter-web" 37 | compile "org.springframework.boot:spring-boot-starter-data-jpa" 38 | compile "org.springframework.boot:spring-boot-starter-thymeleaf" 39 | compile "org.springframework.data:spring-data-neo4j-rest:3.4.6.RELEASE" 40 | compile "org.springframework.data:spring-data-neo4j:4.1.6.RELEASE" 41 | compile "org.neo4j:neo4j-ogm-core:2.0.6" 42 | compile "org.neo4j:neo4j-ogm-http-driver:2.0.6" 43 | 44 | testCompile('org.springframework.boot:spring-boot-starter-test') 45 | } 46 | 47 | bootRepackage { 48 | mainClass = "com.example.DemoApplication" 49 | } 50 | 51 | springBoot { 52 | mainClass = "com.example.DemoApplication" 53 | executable = true 54 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjb/neo4j-mysql-spring-boot/9aadea7812c0b066edc4d981d6a53a244bd3fe50/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/main/java/com/example/DatasourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.hibernate.jpa.HibernatePersistenceProvider; 4 | import org.neo4j.ogm.session.Session; 5 | import org.neo4j.ogm.session.SessionFactory; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 10 | import org.springframework.boot.context.properties.ConfigurationProperties; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | import org.springframework.context.annotation.Primary; 14 | import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; 15 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 16 | import org.springframework.data.neo4j.config.Neo4jConfiguration; 17 | import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; 18 | import org.springframework.data.neo4j.transaction.Neo4jTransactionManager; 19 | import org.springframework.data.transaction.ChainedTransactionManager; 20 | import org.springframework.orm.jpa.JpaTransactionManager; 21 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; 22 | import org.springframework.orm.jpa.vendor.HibernateJpaDialect; 23 | import org.springframework.transaction.PlatformTransactionManager; 24 | import org.springframework.transaction.annotation.EnableTransactionManagement; 25 | 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | 29 | import javax.sql.DataSource; 30 | 31 | @Configuration 32 | @EnableNeo4jRepositories(basePackages = "com.example.graph") 33 | @EnableJpaRepositories(basePackages = "com.example.relational", transactionManagerRef = "mysqlTransactionManager") 34 | @EnableTransactionManagement 35 | public class DatasourceConfig extends Neo4jConfiguration { 36 | 37 | private static final Logger LOG = LoggerFactory.getLogger(DatasourceConfig.class); 38 | 39 | @Bean 40 | public org.neo4j.ogm.config.Configuration getConfiguration() { 41 | org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); 42 | config 43 | .driverConfiguration() 44 | .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver") 45 | .setURI("http://neo4j:root@localhost:7474"); 46 | return config; 47 | } 48 | 49 | @Bean 50 | public SessionFactory getSessionFactory() { 51 | return new SessionFactory(getConfiguration(), "com.example.graph"); 52 | } 53 | 54 | @Bean 55 | public Session getSession() throws Exception { 56 | return super.getSession(); 57 | } 58 | 59 | @Primary 60 | @Bean(name = "dataSource") 61 | @ConfigurationProperties(prefix = "spring.datasource") 62 | public DataSource dataSource() { 63 | return DataSourceBuilder 64 | .create() 65 | .driverClassName("com.mysql.jdbc.Driver") 66 | .build(); 67 | } 68 | 69 | @Primary 70 | @Bean 71 | @Autowired 72 | public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { 73 | LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean(); 74 | entityManagerFactory.setDataSource(dataSource); 75 | entityManagerFactory.setPackagesToScan("com.example.relational"); 76 | entityManagerFactory.setJpaDialect(new HibernateJpaDialect()); 77 | Map jpaProperties = new HashMap<>(); 78 | jpaProperties.put("hibernate.connection.charSet", "UTF-8"); 79 | jpaProperties.put("spring.jpa.hibernate.ddl-auto", "none"); 80 | jpaProperties.put("spring.jpa.hibernate.naming-strategy", "org.springframework.boot.orm.jpa.SpringNamingStrategy"); 81 | jpaProperties.put("hibernate.bytecode.provider", "javassist"); 82 | jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect"); 83 | jpaProperties.put("hibernate.hbm2ddl.auto", "none"); 84 | jpaProperties.put("hibernate.order_inserts", "true"); 85 | jpaProperties.put("hibernate.jdbc.batch_size", "50"); 86 | 87 | entityManagerFactory.setJpaPropertyMap(jpaProperties); 88 | entityManagerFactory.setPersistenceProvider(new HibernatePersistenceProvider()); 89 | return entityManagerFactory; 90 | } 91 | 92 | @Bean 93 | public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { 94 | return new PersistenceExceptionTranslationPostProcessor(); 95 | } 96 | 97 | @Autowired 98 | @Bean(name = "neo4jTransactionManager") 99 | public Neo4jTransactionManager neo4jTransactionManager(Session sessionFactory) { 100 | return new Neo4jTransactionManager(sessionFactory); 101 | } 102 | 103 | @Autowired 104 | @Primary 105 | @Bean(name = "mysqlTransactionManager") 106 | public JpaTransactionManager mysqlTransactionManager(LocalContainerEntityManagerFactoryBean entityManagerFactory) 107 | throws Exception { 108 | return new JpaTransactionManager(entityManagerFactory.getObject()); 109 | } 110 | 111 | 112 | @Autowired 113 | @Bean(name = "transactionManager") 114 | public PlatformTransactionManager transactionManager(Neo4jTransactionManager neo4jTransactionManager, 115 | JpaTransactionManager mysqlTransactionManager) { 116 | return new ChainedTransactionManager( 117 | mysqlTransactionManager, 118 | neo4jTransactionManager 119 | ); 120 | } 121 | } -------------------------------------------------------------------------------- /src/main/java/com/example/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 7 | import org.springframework.context.annotation.ComponentScan; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 10 | 11 | @Configuration 12 | @ComponentScan(value = {"com.example"}) 13 | @EnableAutoConfiguration(exclude = {Neo4jDataAutoConfiguration.class, DataSourceAutoConfiguration.class}) 14 | @EnableWebMvc 15 | public class DemoApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(DemoApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/example/graph/controller/GraphPersonController.java: -------------------------------------------------------------------------------- 1 | package com.example.graph.controller; 2 | 3 | import com.example.graph.domain.GraphPerson; 4 | import com.example.graph.service.GraphPersonService; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | @RequestMapping(value = "/api/v1/graphPerson") 15 | public class GraphPersonController { 16 | 17 | @Autowired 18 | private GraphPersonService graphPersonService; 19 | 20 | @RequestMapping(method = RequestMethod.POST) 21 | public GraphPerson createPerson(@RequestBody GraphPerson graphPerson) { 22 | return graphPersonService.create(graphPerson); 23 | } 24 | 25 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 26 | public GraphPerson getPerson(@PathVariable("id") Long id) { 27 | return graphPersonService.findOne(id); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/example/graph/domain/GraphPerson.java: -------------------------------------------------------------------------------- 1 | package com.example.graph.domain; 2 | 3 | import org.neo4j.ogm.annotation.GraphId; 4 | 5 | import java.io.Serializable; 6 | 7 | public class GraphPerson implements Serializable { 8 | 9 | private static final long serialVersionUID = 3052327829901249416L; 10 | 11 | @GraphId 12 | private Long id; 13 | 14 | private String name; 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/example/graph/repository/GraphPersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.graph.repository; 2 | 3 | import com.example.graph.domain.GraphPerson; 4 | 5 | import org.springframework.data.neo4j.repository.GraphRepository; 6 | 7 | /** 8 | * Created by tbobella on 1/31/17. 9 | */ 10 | public interface GraphPersonRepository extends GraphRepository { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/graph/service/GraphPersonService.java: -------------------------------------------------------------------------------- 1 | package com.example.graph.service; 2 | 3 | import com.example.graph.domain.GraphPerson; 4 | 5 | public interface GraphPersonService { 6 | 7 | GraphPerson create(GraphPerson graphPerson); 8 | 9 | GraphPerson findOne(Long id); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/example/graph/service/GraphPersonServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.graph.service; 2 | 3 | import com.example.graph.domain.GraphPerson; 4 | import com.example.graph.repository.GraphPersonRepository; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class GraphPersonServiceImpl implements GraphPersonService { 11 | 12 | @Autowired 13 | private GraphPersonRepository graphPersonRepository; 14 | 15 | @Override 16 | public GraphPerson create(GraphPerson graphPerson) { 17 | return graphPersonRepository.save(graphPerson); 18 | } 19 | 20 | @Override 21 | public GraphPerson findOne(Long id) { 22 | return graphPersonRepository.findOne(id); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/example/relational/controller/PersonController.java: -------------------------------------------------------------------------------- 1 | package com.example.relational.controller; 2 | 3 | import com.example.relational.domain.Person; 4 | import com.example.relational.service.PersonService; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | @RequestMapping(value = "/api/v1/person") 15 | public class PersonController { 16 | 17 | @Autowired 18 | private PersonService personService; 19 | 20 | @RequestMapping(method = RequestMethod.POST) 21 | public Person createPerson(@RequestBody Person person) { 22 | return personService.create(person); 23 | } 24 | 25 | @RequestMapping(value = "/{id}", method = RequestMethod.GET) 26 | public Person getPerson(@PathVariable("id") Long id) { 27 | return personService.findOne(id); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/example/relational/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.example.relational.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | public class Person implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private Long id; 19 | 20 | @Column 21 | private String name; 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public Long getId() { 32 | return id; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/example/relational/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.relational.repository; 2 | 3 | import com.example.relational.domain.Person; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | public interface PersonRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/example/relational/service/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.example.relational.service; 2 | 3 | import com.example.relational.domain.Person; 4 | 5 | 6 | public interface PersonService { 7 | 8 | Person create(Person person); 9 | 10 | Person findOne(Long id); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/relational/service/PersonServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.relational.service; 2 | 3 | import com.example.relational.domain.Person; 4 | import com.example.relational.repository.PersonRepository; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class PersonServiceImpl implements PersonService { 11 | 12 | @Autowired 13 | private PersonRepository personRepository; 14 | 15 | @Override 16 | public Person create(Person person) { 17 | return personRepository.save(person); 18 | } 19 | 20 | @Override 21 | public Person findOne(Long id) { 22 | return personRepository.findOne(id); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | neo4j: 4 | username: neo4j 5 | password: root 6 | session: 7 | scope: session 8 | datasource: 9 | url: jdbc:mysql://127.0.0.1:3306/test?useSSL=false 10 | username: root 11 | password: 12 | platform: mysql 13 | -------------------------------------------------------------------------------- /src/test/java/com/example/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------