Commit db2c54e0 authored by zhengfunan's avatar zhengfunan

读取配置文件

parent da6e5c16
......@@ -4,15 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="67e936c8-2d55-4655-871e-e6e153e4d8e1" name="更改" comment="stater版首次提交">
<list default="true" id="67e936c8-2d55-4655-871e-e6e153e4d8e1" name="更改" comment="修改路径">
<change afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/config/RawConfigUtil.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/auto/Neo4jAutoConfiguration.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/auto/Neo4jAutoConfiguration.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/config/Neo4jProperties.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/config/Neo4jProperties.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/neo4j/Neo4jServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/neo4j/Neo4jServer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/service/TDGraphService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/service/TDGraphService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/tasks/SynchronizeMetadata.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/tasks/SynchronizeMetadata.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tddopo/util/GraphUtil.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/util/GraphUtil.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/META-INF/spring.factories" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/META-INF/spring.factories" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/auto/Neo4jAutoConfiguration.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/auto/Neo4jAutoConfiguration.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/neo4j/Neo4jServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/neo4j/Neo4jServer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/service/TDGraphService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tongda/tdtopo/service/TDGraphService.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -103,7 +100,8 @@
<workItem from="1693386223381" duration="3004000" />
<workItem from="1693447950473" duration="11267000" />
<workItem from="1693536669710" duration="10048000" />
<workItem from="1693622693690" duration="1530000" />
<workItem from="1693622693690" duration="19250000" />
<workItem from="1693802539121" duration="124000" />
</task>
<task id="LOCAL-00001" summary="stater版首次提交">
<created>1693387558801</created>
......@@ -119,7 +117,14 @@
<option name="project" value="LOCAL" />
<updated>1693545997120</updated>
</task>
<option name="localTasksCounter" value="3" />
<task id="LOCAL-00003" summary="修改路径">
<created>1693626349609</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1693626349609</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
......@@ -127,6 +132,7 @@
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="stater版首次提交" />
<option name="LAST_COMMIT_MESSAGE" value="stater版首次提交" />
<MESSAGE value="修改路径" />
<option name="LAST_COMMIT_MESSAGE" value="修改路径" />
</component>
</project>
\ No newline at end of file
......@@ -3,7 +3,9 @@ package com.tongda.tdtopo.auto;
import com.tongda.tdtopo.config.Neo4jProperties;
import com.tongda.tdtopo.neo4j.Neo4jServer;
import com.tongda.tdtopo.service.TDGraphService;
import lombok.Data;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
......@@ -18,15 +20,23 @@ public class Neo4jAutoConfiguration {
@Resource
private Neo4jProperties properties; // 使用配置
@Bean
@ConditionalOnMissingBean
public GraphDatabaseService init() {
public Neo4jAutoConfiguration(Neo4jProperties properties) {
this.properties = properties;
this.init();
}
public void init() {
//初始化neo4j
GraphDatabaseService graphDatabaseService=new Neo4jServer().init(properties.getPath(),properties.getBolt());
System.out.println("neo4j-server启动成功");
TDGraphService tdGraphService=new TDGraphService();
System.out.println(tdGraphService.searchRelationType());
return graphDatabaseService;
// GraphDatabaseService graphDatabaseService=Neo4jServer.init(properties.getPath(),properties.getBolt());
// Neo4jServer.path=properties.getPath();
System.out.println(properties.getPath()+"/"+properties.getBolt());
// Neo4jServer.neo4jInit();
// System.out.println("neo4j-server启动成功");
// TDGraphService tdGraphService=new TDGraphService();
// System.out.println(tdGraphService.searchRelationType());
}
......
package com.tongda.tdtopo.config;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
import java.util.Properties;
public class RawConfigUtil {
private static Properties properties = readProperties("application.properties");
private static Properties readProperties(String... confFile) {
final Properties properties = new Properties();
try {
for (String path : confFile) {
final ClassPathResource resource = new ClassPathResource(path);
properties.load(resource.getInputStream());
}
} catch (IOException e) {
e.printStackTrace();
}
return properties;
}
public static String getString(String key) {
return properties.getProperty(key);
}
}
package com.tongda.tdtopo.neo4j;
import com.tongda.tdtopo.config.Neo4jProperties;
import com.tongda.tdtopo.config.RawConfigUtil;
import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
......@@ -10,17 +12,28 @@ import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.graphdb.schema.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.File;
import java.util.HashMap;
@Configuration
@Component
public class Neo4jServer {
public static GraphDatabaseService graphDatabaseService;
public static GraphDatabaseService getGraphDatabaseServiceIn() {
if (graphDatabaseService==null){
graphDatabaseService = neo4jInit();
}
return graphDatabaseService;
}
// @Value("${neo4j.path}")
public static String path= RawConfigUtil.getString("neo4j.path");
public static GraphDatabaseService graphDatabaseService=getGraphDatabaseServiceIn();
// public static DatabaseManagementService managementService;
......@@ -28,33 +41,41 @@ public class Neo4jServer {
// private Environment environment;
// @PostConstruct
public GraphDatabaseService init(String file,String bolt){
GraphDatabaseSettings.BoltConnector boltConnector = GraphDatabaseSettings.boltConnector( "0" );
public static GraphDatabaseService neo4jInit(){
System.out.println("配置"+path+graphDatabaseService);
if (path!=null&&graphDatabaseService==null){
GraphDatabaseSettings.BoltConnector boltConnector = GraphDatabaseSettings.boltConnector( "0" );
graphDatabaseService = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(new File(file))
.setConfig( GraphDatabaseSettings.pagecache_memory, "8192M" )
.setConfig( GraphDatabaseSettings.string_block_size, "600" )
.setConfig( GraphDatabaseSettings.array_block_size, "3000" )
graphDatabaseService = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(new File(path))
// .newEmbeddedDatabaseBuilder(new File("neo4j"))
.setConfig( GraphDatabaseSettings.pagecache_memory, "8192M" )
.setConfig( GraphDatabaseSettings.string_block_size, "600" )
.setConfig( GraphDatabaseSettings.array_block_size, "3000" )
// .setConfig( boltConnector.type, "BOLT" )
// .setConfig( boltConnector.enabled, "true" )
// .setConfig( boltConnector.address, "localhost:7687")
.newGraphDatabase();
IndexDefinition indexDefinition;
try ( Transaction tx = graphDatabaseService.beginTx() )
{
Schema schema = graphDatabaseService.schema();
indexDefinition = schema.indexFor( Label.label( "MDE" ))
.on( "id" )
.create();
indexDefinition = schema.indexFor( Label.label( "AST" ))
.on( "id" )
.create();
tx.success();
}catch (ConstraintViolationException e){
System.out.println("index 已经建立");
.newGraphDatabase();
System.out.println("neo4j-server启动");
IndexDefinition indexDefinition;
try ( Transaction tx = graphDatabaseService.beginTx() )
{
Schema schema = graphDatabaseService.schema();
indexDefinition = schema.indexFor( Label.label( "MDE" ))
.on( "id" )
.create();
indexDefinition = schema.indexFor( Label.label( "AST" ))
.on( "id" )
.create();
tx.success();
}catch (ConstraintViolationException e){
System.out.println("index 已经建立");
}
return graphDatabaseService;
}
return graphDatabaseService;
System.out.println("初始化搁置");
return null;
}
// private static void registerShutdownHook( final GraphDatabaseService graphDb )
......
......@@ -11,6 +11,7 @@ import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.neo4j.graphdb.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream;
......@@ -20,7 +21,9 @@ import java.util.*;
@Service
public class TDGraphService {
GraphDatabaseService graphDb= Neo4jServer.graphDatabaseService;
private GraphDatabaseService graphDb=new Neo4jServer().getGraphDatabaseServiceIn();
public static HashMap<String ,String> keymap=new HashMap<>();
static {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment