1、引入对应的包:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency>
2、写server启动入口:
@SpringBootApplication public class ServerApp { public static void main(String[] args) { SpringApplication.run(ServerApp.class, args); } }
3、写对应的ApiController:其中一个子函数就是一个请求服务
@RestController public class ApiController { private SearchPoi searchGd = new SearchPoi(); private PartMatchPro partMatchPro = new PartMatchPro(); private StaticGd staticGd = new StaticGd(); private MakeIndexProduct makeIndexProduct = new MakeIndexProduct(); private PoiOnRoad poiOnRoad = new PoiOnRoad(); @RequestMapping("/test") public String testMethod(String param){ return "Hello"+param; // return new AmapShow().getamapinfo(); } //高德抓取源接入统计相关 @RequestMapping("/gdstatic") public String staticGd(){ return staticGd.staticGd(); } //根据传入数据的名称和经纬度,获取相关索引的全部成品数据 @RequestMapping("/SearchPoi1") public String tijiaobiaodan(){ String s = searchGd.tijiaobiaodan(); return s; } @PostMapping("/searchresult") public String searchresult(@RequestParam("name") String name, @RequestParam("latlng") String latlng, @RequestParam("n") int n){ return searchGd.searchpoi(name, latlng, n); } //根据传入的基础数据信息,返回成品库中匹配结果 @RequestMapping("/MatchPoi") public String matchtijiaobiaodan(){ String s = partMatchPro.tijiaoBiaodan(); return s; } @PostMapping("/matchresult") public String matchresult(@RequestParam("poi_id") String poi_id, @RequestParam("name") String name, @RequestParam("name_alias") String name_alias, @RequestParam("address") String address, @RequestParam("tel") String tel, @RequestParam("category_id") String category_id, @RequestParam("lnglat") String lnglat){ return partMatchPro.partMatchPro(poi_id, name, name_alias, address, tel, category_id, lnglat); } //传入名称、坐标和返回数量,返回gd索引库中相关的排序靠前n的poi数据 @RequestMapping("/SearchPoi") public String SearchPoi(String name, double lat, double lng, int n){ String s = searchGd.searchpoi(name, lat + "," + lng, n); return s; } //传入成品数据的基础信息,对成品数据构建索引 @RequestMapping("/MakeIndexProduct") public String makeindexProduct(@RequestBody JSONObject jsonParam){ String s = makeIndexProduct.makeIndexProduct(jsonParam.getString("poi_id"), jsonParam.getString("name") , jsonParam.getString("name_alias"), jsonParam.getString("address"), jsonParam.getString("category_id"), jsonParam.getString("category_name"), jsonParam.getDouble("latitude"), jsonParam.getDouble("longitude"), jsonParam.getString("tel"), jsonParam.getString("entry"), jsonParam.getString("city_code"), jsonParam.getString("name_ner")); return s; } //压路服务,根据传入的经纬度,判断是否压力,并返回推荐坐标 @RequestMapping("/PoiOnRoad") public String PoiOnRoad(String lnglat){ String s = poiOnRoad.poiOnRoadServer(lnglat); return s; } }
本机测试时:直接启动ServerApp中即可
然后调用本机服务:比如:
http://localhost:8092/test?param=test
打包部署到服务器上时,需要在pom.xml中配置:
<sourceDirectory>src/main/java</sourceDirectory> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugin>
对应jar包上传到服务器上之后,启动:nohup java -jar acmp-1.0-SNAPSHOT.jar > mylog.log 2>&1 &
直接调用即可
注意:
普通工程打包时需要要对应的boot注掉
完整的pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.13</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>acmp</artifactId> <version>1.0-SNAPSHOT</version> <!-- <packaging>jar</packaging>--> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jpmml</groupId> <artifactId>pmml-evaluator</artifactId> <version>1.4.1</version> </dependency> <dependency> <groupId>org.jpmml</groupId> <artifactId>pmml-evaluator-extension</artifactId> <version>1.4.15</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.2</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers-common</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers-smartcn</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-queryparser</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-highlighter</artifactId> <version>5.3.1</version> </dependency> <dependency> <groupId>com.github.magese</groupId> <artifactId>ik-analyzer</artifactId> <version>7.6.0</version> </dependency> <dependency> <groupId>com.ibm.icu</groupId> <artifactId>icu4j</artifactId> <version>69.1</version> </dependency> <dependency> <groupId>com.github.stuxuhai</groupId> <artifactId>jpinyin</artifactId> <version>1.1.8</version> </dependency> <dependency> <groupId>com.hankcs</groupId> <artifactId>hanlp</artifactId> <version>portable-1.7.8</version> </dependency> <dependency> <groupId>org.ansj</groupId> <artifactId>ansj_seg</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> <version>4.4</version> </dependency> <dependency> <groupId>com.huaban</groupId> <artifactId>jieba-analysis</artifactId> <version>1.0.2</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.7.0</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>net.sf.ezmorph</groupId> <artifactId>ezmorph</artifactId> <version>1.0.3</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>com.uber</groupId> <artifactId>h3</artifactId> <version>3.4.0</version> </dependency> <dependency> <groupId>org.python</groupId> <artifactId>jython-standalone</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.24</version> </dependency> <dependency> <groupId>com.github.houbb</groupId> <artifactId>opencc4j</artifactId> <version>1.0.2</version> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.3.3</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-shapefile</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-api</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-geojson</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-geometry</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-jts-wrapper</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-main</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-opengis</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-data</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-referencing</artifactId> <version>20.3</version> </dependency> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>2.8.0</version> </dependency> </dependencies> <build> <sourceDirectory>src/main/java</sourceDirectory> <plugins> <!-- <plugin>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-maven-plugin</artifactId>--> <!-- </plugin>--> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass></mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>langge</id> <name>langge</name> <url>****</url> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>langge</id> <name>langge</name> <url>****</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> </project>