Переглянути джерело

改成外置的tomcat部署

houweiyu 4 роки тому
батько
коміт
92b7f260a0

+ 21 - 1
pom.xml

@@ -10,7 +10,8 @@
     <description>房车宝管理后台综合管理微服务</description>
 
 
-    <packaging>jar</packaging>
+    <!--<packaging>jar</packaging>-->
+    <packaging>war</packaging>
 
 
     <properties>
@@ -79,6 +80,10 @@
                     <groupId>commons-io</groupId>
                     <artifactId>commons-io</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-tomcat</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <!-- nacos 配置中心依赖 -->
@@ -123,6 +128,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-tomcat</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.rocketmq</groupId>
             <artifactId>rocketmq-spring-boot-starter</artifactId>
             <version>2.1.1</version>
@@ -188,6 +199,15 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 

+ 8 - 1
src/main/java/fcb/project/manager/FcbProjectManagerApplication.java

@@ -7,6 +7,8 @@ import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.Bean;
@@ -25,7 +27,7 @@ import java.time.format.DateTimeFormatter;
 @EnableDiscoveryClient
 @SpringBootApplication(scanBasePackages = {"fdage.back.sdk.core" , "fcb.project.manager" , "fdage.back.sdk.base.swagger"})
 @MapperScan(basePackages = {"fcb.project.manager.base.dao"})
-public class FcbProjectManagerApplication {
+public class FcbProjectManagerApplication extends SpringBootServletInitializer {
 
     @Bean
     public ObjectMapper serializingObjectMapper() {
@@ -41,6 +43,11 @@ public class FcbProjectManagerApplication {
 
     }
 
+    @Override
+    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+        return application.sources(FcbProjectManagerApplication.class);
+    }
+
 
     public static void main(String[] args) {
         SpringApplication springApplication = new SpringApplication(FcbProjectManagerApplication.class);

+ 34 - 0
src/main/java/fcb/project/manager/base/config/MyNacosLifecycle.java

@@ -0,0 +1,34 @@
+package fcb.project.manager.base.config;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.alibaba.nacos.registry.NacosAutoServiceRegistration;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+
+/**
+ * 2 * @Author: Abner
+ * 3 * @Date: 2021/1/29 13:59
+ * 4
+ */
+@Configuration
+public class MyNacosLifecycle implements ApplicationContextAware {
+
+    @Autowired(required = false)
+    private NacosAutoServiceRegistration registration;
+
+    @Autowired
+    private Environment environment;
+
+    @Override
+    public void setApplicationContext(ApplicationContext context) throws BeansException {
+        if (registration != null) {
+            String port = environment.getProperty("server.port");
+            registration.setPort(Integer.parseInt(port));
+            registration.start();
+        }
+    }
+}
+

+ 1 - 0
src/main/resources/application-prod.properties

@@ -1,5 +1,6 @@
 
 server.port=8285
+#server.port=8385
 
 #注册中心
 spring.cloud.nacos.discovery.server-addr=10.71.5.163:80

+ 1 - 0
src/main/resources/application-test.properties

@@ -1,5 +1,6 @@
 
 server.port=8285
+#server.port=8385
 
 #注册中心
 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848

+ 2 - 2
src/main/resources/application.properties

@@ -1,8 +1,8 @@
 
 
-#spring.profiles.active=prod
+spring.profiles.active=prod
 #spring.profiles.active=dev
-spring.profiles.active=test
+#spring.profiles.active=test
 
 #应用名
 spring.application.name=fbc-project-manager