Ver código fonte

update war to tomcat

wuweihao 5 anos atrás
pai
commit
8741491d0d

+ 1 - 1
pom.xml

@@ -12,7 +12,7 @@
     <artifactId>air-conditioning</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <name>air</name>
-    <packaging>jar</packaging>
+    <packaging>war</packaging>
     <description>Demo project for Spring Boot</description>
 
     <properties>

+ 2 - 2
src/main/java/com/fd/AirApplication.java

@@ -4,12 +4,12 @@ package com.fd;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 
 
 @Log4j2
 @SpringBootApplication
-public class AirApplication {
+public class AirApplication extends SpringBootServletInitializer {
 
     public static void main(String[] args) {
         SpringApplication.run(AirApplication.class, args);

+ 44 - 37
src/main/java/com/fd/controller/DataController.java

@@ -51,6 +51,10 @@ public class DataController {
     private Socket client;
 
 
+    /**
+     * 初始化
+     * @return
+     */
     @PostConstruct
     private Socket init() {
         // 1 建立连接
@@ -72,43 +76,6 @@ public class DataController {
     }
 
 
-    // 返回前端总入口
-    @GetMapping("data")
-    @SuppressWarnings({"rawtypes", "unchecked"})
-    private ResponseEntity getData() {
-        log.info("run getData");
-//        List connect = PythonUtils.connect(exePath, command);
-        List<Object> list = new ArrayList<>();
-        for (int i = 1; i < 99; i++) {
-            Classroom classroom = new Classroom();
-            classroom.setId(i);
-            classroom.setRegion(DataFormatUtils.randomInt(3, 1));
-            classroom.setStatus(DataFormatUtils.randomInt(2, 0));
-            classroom.setStorey(DataFormatUtils.randomInt(10, 1));
-            classroom.setCount(DataFormatUtils.randomInt(50, 20));
-            list.add(classroom);
-        }
-
-        try {
-            Thread.sleep(9000);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        return new ResponseEntity(list, HttpStatus.OK);
-    }
-
-
-    /**
-     * 测试算法
-     */
-    @GetMapping("p")
-    @SuppressWarnings({"rawtypes", "unchecked"})
-    private ResponseEntity getData1() {
-        log.info("run testPython");
-        List connect = PythonUtils.connect(exePath, command);
-        return new ResponseEntity(connect, HttpStatus.OK);
-    }
-
 
     /**
      * 重启socket客户端
@@ -160,6 +127,46 @@ public class DataController {
         return new ResponseEntity(result, HttpStatus.OK);
     }
 
+    // ===================================== 测试用 ========================================================
+
+
+    // 返回前端总入口
+    @GetMapping("data")
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    private ResponseEntity getData() {
+        log.info("run getData");
+//        List connect = PythonUtils.connect(exePath, command);
+        List<Object> list = new ArrayList<>();
+        for (int i = 1; i < 99; i++) {
+            Classroom classroom = new Classroom();
+            classroom.setId(i);
+            classroom.setRegion(DataFormatUtils.randomInt(3, 1));
+            classroom.setStatus(DataFormatUtils.randomInt(2, 0));
+            classroom.setStorey(DataFormatUtils.randomInt(10, 1));
+            classroom.setCount(DataFormatUtils.randomInt(50, 20));
+            list.add(classroom);
+        }
+
+        try {
+            Thread.sleep(3000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        return new ResponseEntity(list, HttpStatus.OK);
+    }
+
+
+    /**
+     * 测试算法
+     */
+    @GetMapping("p")
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    private ResponseEntity getDataP() {
+        log.info("run testPython");
+        List connect = PythonUtils.connect(exePath, command);
+        return new ResponseEntity(connect, HttpStatus.OK);
+    }
+
     // test cpp
     @GetMapping("6")
     @SuppressWarnings({"rawtypes", "unchecked"})

+ 4 - 0
src/main/resources/application.yml

@@ -1,5 +1,7 @@
 server:
   port: 8086
+  servlet:
+    context-path: /air  #2.0 访问项目名称
 
 socket:
   ipAddress: 127.0.0.1
@@ -19,3 +21,5 @@ logging:
 
 
 
+
+