mybtisplus 配置neo4j jdbc 完整代码
时间: 2023-12-31 15:04:15 浏览: 97
jdbc资源全套配置
以下是使用 MyBatis Plus 配置 Neo4j JDBC 的完整代码示例:
首先,在 pom.xml 文件中添加以下依赖:
```xml
<dependencies>
<!-- MyBatis Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.1</version>
</dependency>
<!-- Neo4j JDBC driver -->
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-jdbc-driver</artifactId>
<version>4.3.0</version>
</dependency>
</dependencies>
```
然后,在 application.properties 文件中添加以下配置:
```properties
# Neo4j JDBC
spring.datasource.url=jdbc:neo4j:bolt://localhost:7687
spring.datasource.username=neo4j
spring.datasource.password=neo4j
spring.datasource.driver-class-name=org.neo4j.jdbc.Driver
```
最后,在 MyBatis Plus 的配置类中添加以下配置:
```java
@Configuration
@MapperScan("com.example.mapper")
public class MybatisPlusConfig {
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.driver-class-name}")
private String driverClass;
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
factoryBean.setDataSource(dataSource());
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
factoryBean.setMapperLocations(resolver.getResources("classpath*:/mapper/**/*.xml"));
return factoryBean.getObject();
}
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
}
```
其中,@MapperScan 注解中的 com.example.mapper 是你的 Mapper 接口所在的包路径,需要根据自己的实际情况进行修改。
这样,就完成了 MyBatis Plus 配置 Neo4j JDBC 的过程。
阅读全文