Commit db2c54e0 authored by zhengfunan's avatar zhengfunan

读取配置文件

parent da6e5c16
...@@ -4,15 +4,12 @@ ...@@ -4,15 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <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$/.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/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/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/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/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/tdtopo/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/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" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -103,7 +100,8 @@ ...@@ -103,7 +100,8 @@
<workItem from="1693386223381" duration="3004000" /> <workItem from="1693386223381" duration="3004000" />
<workItem from="1693447950473" duration="11267000" /> <workItem from="1693447950473" duration="11267000" />
<workItem from="1693536669710" duration="10048000" /> <workItem from="1693536669710" duration="10048000" />
<workItem from="1693622693690" duration="1530000" /> <workItem from="1693622693690" duration="19250000" />
<workItem from="1693802539121" duration="124000" />
</task> </task>
<task id="LOCAL-00001" summary="stater版首次提交"> <task id="LOCAL-00001" summary="stater版首次提交">
<created>1693387558801</created> <created>1693387558801</created>
...@@ -119,7 +117,14 @@ ...@@ -119,7 +117,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1693545997120</updated> <updated>1693545997120</updated>
</task> </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 /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
...@@ -127,6 +132,7 @@ ...@@ -127,6 +132,7 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="stater版首次提交" /> <MESSAGE value="stater版首次提交" />
<option name="LAST_COMMIT_MESSAGE" value="stater版首次提交" /> <MESSAGE value="修改路径" />
<option name="LAST_COMMIT_MESSAGE" value="修改路径" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -3,7 +3,9 @@ package com.tongda.tdtopo.auto; ...@@ -3,7 +3,9 @@ package com.tongda.tdtopo.auto;
import com.tongda.tdtopo.config.Neo4jProperties; import com.tongda.tdtopo.config.Neo4jProperties;
import com.tongda.tdtopo.neo4j.Neo4jServer; import com.tongda.tdtopo.neo4j.Neo4jServer;
import com.tongda.tdtopo.service.TDGraphService; import com.tongda.tdtopo.service.TDGraphService;
import lombok.Data;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -18,15 +20,23 @@ public class Neo4jAutoConfiguration { ...@@ -18,15 +20,23 @@ public class Neo4jAutoConfiguration {
@Resource @Resource
private Neo4jProperties properties; // 使用配置 private Neo4jProperties properties; // 使用配置
@Bean public Neo4jAutoConfiguration(Neo4jProperties properties) {
@ConditionalOnMissingBean this.properties = properties;
public GraphDatabaseService init() { this.init();
}
public void init() {
//初始化neo4j //初始化neo4j
GraphDatabaseService graphDatabaseService=new Neo4jServer().init(properties.getPath(),properties.getBolt()); // GraphDatabaseService graphDatabaseService=Neo4jServer.init(properties.getPath(),properties.getBolt());
System.out.println("neo4j-server启动成功"); // Neo4jServer.path=properties.getPath();
TDGraphService tdGraphService=new TDGraphService();
System.out.println(tdGraphService.searchRelationType()); System.out.println(properties.getPath()+"/"+properties.getBolt());
return graphDatabaseService; // 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; 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.ConstraintViolationException;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
...@@ -10,17 +12,28 @@ import org.neo4j.graphdb.factory.GraphDatabaseSettings; ...@@ -10,17 +12,28 @@ import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.schema.IndexDefinition; import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.graphdb.schema.Schema; import org.neo4j.graphdb.schema.Schema;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; 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.io.File;
import java.util.HashMap;
@Configuration @Component
public class Neo4jServer { 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; // public static DatabaseManagementService managementService;
...@@ -28,11 +41,15 @@ public class Neo4jServer { ...@@ -28,11 +41,15 @@ public class Neo4jServer {
// private Environment environment; // private Environment environment;
// @PostConstruct // @PostConstruct
public GraphDatabaseService init(String file,String bolt){ public static GraphDatabaseService neo4jInit(){
System.out.println("配置"+path+graphDatabaseService);
if (path!=null&&graphDatabaseService==null){
GraphDatabaseSettings.BoltConnector boltConnector = GraphDatabaseSettings.boltConnector( "0" ); GraphDatabaseSettings.BoltConnector boltConnector = GraphDatabaseSettings.boltConnector( "0" );
graphDatabaseService = new GraphDatabaseFactory() graphDatabaseService = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(new File(file)) .newEmbeddedDatabaseBuilder(new File(path))
// .newEmbeddedDatabaseBuilder(new File("neo4j"))
.setConfig( GraphDatabaseSettings.pagecache_memory, "8192M" ) .setConfig( GraphDatabaseSettings.pagecache_memory, "8192M" )
.setConfig( GraphDatabaseSettings.string_block_size, "600" ) .setConfig( GraphDatabaseSettings.string_block_size, "600" )
.setConfig( GraphDatabaseSettings.array_block_size, "3000" ) .setConfig( GraphDatabaseSettings.array_block_size, "3000" )
...@@ -40,6 +57,7 @@ public class Neo4jServer { ...@@ -40,6 +57,7 @@ public class Neo4jServer {
// .setConfig( boltConnector.enabled, "true" ) // .setConfig( boltConnector.enabled, "true" )
// .setConfig( boltConnector.address, "localhost:7687") // .setConfig( boltConnector.address, "localhost:7687")
.newGraphDatabase(); .newGraphDatabase();
System.out.println("neo4j-server启动");
IndexDefinition indexDefinition; IndexDefinition indexDefinition;
try ( Transaction tx = graphDatabaseService.beginTx() ) try ( Transaction tx = graphDatabaseService.beginTx() )
{ {
...@@ -56,6 +74,9 @@ public class Neo4jServer { ...@@ -56,6 +74,9 @@ public class Neo4jServer {
} }
return graphDatabaseService; return graphDatabaseService;
} }
System.out.println("初始化搁置");
return null;
}
// private static void registerShutdownHook( final GraphDatabaseService graphDb ) // private static void registerShutdownHook( final GraphDatabaseService graphDb )
// { // {
......
...@@ -11,6 +11,7 @@ import org.dom4j.DocumentException; ...@@ -11,6 +11,7 @@ import org.dom4j.DocumentException;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.neo4j.graphdb.*; import org.neo4j.graphdb.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
...@@ -20,7 +21,9 @@ import java.util.*; ...@@ -20,7 +21,9 @@ import java.util.*;
@Service @Service
public class TDGraphService { public class TDGraphService {
GraphDatabaseService graphDb= Neo4jServer.graphDatabaseService;
private GraphDatabaseService graphDb=new Neo4jServer().getGraphDatabaseServiceIn();
public static HashMap<String ,String> keymap=new HashMap<>(); public static HashMap<String ,String> keymap=new HashMap<>();
static { 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