Ver código fonte

启动类中加入异常捕获处理

wuxw 6 anos atrás
pai
commit
7a3fba8ac0

+ 7 - 3
Api/src/main/java/com/java110/api/ApiApplicationStart.java

@@ -117,10 +117,14 @@ public class ApiApplicationStart {
 
 
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(ApiApplicationStart.class, args);
+        try{
+            ApplicationContext context = SpringApplication.run(ApiApplicationStart.class, args);
 
 
-        //服务启动加载
-        ServiceStartInit.initSystemConfig(context);
+            //服务启动加载
+            ServiceStartInit.initSystemConfig(context);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 
 
 }
 }

+ 6 - 2
CommentService/src/main/java/com/java110/comment/CommentServiceApplicationStart.java

@@ -51,7 +51,11 @@ public class CommentServiceApplicationStart {
     }
     }
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(CommentServiceApplicationStart.class, args);
-        ServiceStartInit.initSystemConfig(context);
+        try{
+            ApplicationContext context = SpringApplication.run(CommentServiceApplicationStart.class, args);
+            ServiceStartInit.initSystemConfig(context);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 6 - 2
CommunityService/src/main/java/com/java110/community/CommunityServiceApplicationStart.java

@@ -64,7 +64,11 @@ public class CommunityServiceApplicationStart {
     }
     }
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(CommunityServiceApplicationStart.class, args);
-        ServiceStartInit.initSystemConfig(context);
+        try{
+            ApplicationContext context = SpringApplication.run(CommunityServiceApplicationStart.class, args);
+            ServiceStartInit.initSystemConfig(context);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 6 - 2
FeeService/src/main/java/com/java110/fee/FeeServiceApplicationStart.java

@@ -52,7 +52,11 @@ public class FeeServiceApplicationStart {
     }
     }
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(FeeServiceApplicationStart.class, args);
-        ServiceStartInit.initSystemConfig(context);
+        try{
+            ApplicationContext context = SpringApplication.run(FeeServiceApplicationStart.class, args);
+            ServiceStartInit.initSystemConfig(context);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 9 - 3
LogService/src/main/java/com/java110/log/LogServiceApplicationStart.java

@@ -5,6 +5,8 @@ package com.java110.log;
  */
  */
 
 
 import com.java110.service.init.ServiceStartInit;
 import com.java110.service.init.ServiceStartInit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -25,13 +27,17 @@ import org.springframework.context.ApplicationContext;
 @EnableDiscoveryClient
 @EnableDiscoveryClient
 @EnableFeignClients(basePackages = {"com.java110.core.smo"})
 @EnableFeignClients(basePackages = {"com.java110.core.smo"})
 public class LogServiceApplicationStart {
 public class LogServiceApplicationStart {
+    private static Logger logger = LoggerFactory.getLogger(LogServiceApplicationStart.class);
 
 
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
+        try{
+            ApplicationContext context =  SpringApplication.run(LogServiceApplicationStart.class, args);
 
 
-        ApplicationContext context =  SpringApplication.run(LogServiceApplicationStart.class, args);
-
-        ServiceStartInit.initSystemConfig(context);
+            ServiceStartInit.initSystemConfig(context);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
 
 
     }
     }
 }
 }

+ 11 - 7
OrderService/src/main/java/com/java110/order/OrderServiceApplicationStart.java

@@ -69,16 +69,20 @@ public class OrderServiceApplicationStart {
     }
     }
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(OrderServiceApplicationStart.class, args);
+        try {
+            ApplicationContext context = SpringApplication.run(OrderServiceApplicationStart.class, args);
 
 
-        //服务启动加载
-        ServiceStartInit.initSystemConfig(context);
+            //服务启动加载
+            ServiceStartInit.initSystemConfig(context);
 
 
-        //加载事件数据
-        //EventConfigInit.initSystemConfig();
+            //加载事件数据
+            //EventConfigInit.initSystemConfig();
 
 
-        //刷新缓存
-        flushMainCache(args);
+            //刷新缓存
+            flushMainCache(args);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 
 
 
 

+ 5 - 1
RuleService/src/main/java/com/java110/rule/AppSpringBootApplication.java

@@ -29,6 +29,10 @@ public class AppSpringBootApplication {
 
 
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        SpringApplication.run(AppSpringBootApplication.class, args);
+        try{
+            SpringApplication.run(AppSpringBootApplication.class, args);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 8 - 4
ShopService/src/main/java/com/java110/shop/ShopServiceApplicationStart.java

@@ -52,9 +52,13 @@ public class ShopServiceApplicationStart {
     }
     }
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(ShopServiceApplicationStart.class, args);
-        ServiceStartInit.initSystemConfig(context);
-        //加载业务侦听
-        //SystemStartLoadBusinessConfigure.initSystemConfig(LISTENER_PATH);
+        try{
+            ApplicationContext context = SpringApplication.run(ShopServiceApplicationStart.class, args);
+            ServiceStartInit.initSystemConfig(context);
+            //加载业务侦听
+            //SystemStartLoadBusinessConfigure.initSystemConfig(LISTENER_PATH);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 8 - 4
StoreService/src/main/java/com/java110/store/StoreServiceApplicationStart.java

@@ -63,9 +63,13 @@ public class StoreServiceApplicationStart {
     }
     }
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(StoreServiceApplicationStart.class, args);
-        ServiceStartInit.initSystemConfig(context);
-        //加载业务侦听
-        //SystemStartLoadBusinessConfigure.initSystemConfig(LISTENER_PATH);
+        try {
+            ApplicationContext context = SpringApplication.run(StoreServiceApplicationStart.class, args);
+            ServiceStartInit.initSystemConfig(context);
+            //加载业务侦听
+            //SystemStartLoadBusinessConfigure.initSystemConfig(LISTENER_PATH);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 8 - 4
UserService/src/main/java/com/java110/user/UserServiceApplicationStart.java

@@ -56,9 +56,13 @@ public class UserServiceApplicationStart {
     }
     }
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(UserServiceApplicationStart.class, args);
-        ServiceStartInit.initSystemConfig(context);
-        //加载业务侦听
-        // SystemStartLoadBusinessConfigure.initSystemConfig(LISTENER_PATH);
+        try{
+            ApplicationContext context = SpringApplication.run(UserServiceApplicationStart.class, args);
+            ServiceStartInit.initSystemConfig(context);
+            //加载业务侦听
+            // SystemStartLoadBusinessConfigure.initSystemConfig(LISTENER_PATH);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 12 - 3
WebService/src/main/java/com/java110/web/WebServiceApplicationStart.java

@@ -2,6 +2,8 @@ package com.java110.web;
 
 
 import com.java110.service.init.ServiceStartInit;
 import com.java110.service.init.ServiceStartInit;
 import com.java110.web.core.VueComponentTemplate;
 import com.java110.web.core.VueComponentTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -36,6 +38,9 @@ import java.nio.charset.Charset;
 @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
 @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
 public class WebServiceApplicationStart {
 public class WebServiceApplicationStart {
 
 
+    private static Logger logger = LoggerFactory.getLogger(WebServiceApplicationStart.class);
+
+
     /**
     /**
      * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
      * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
      *
      *
@@ -51,8 +56,12 @@ public class WebServiceApplicationStart {
 
 
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        ApplicationContext context = SpringApplication.run(WebServiceApplicationStart.class, args);
-        ServiceStartInit.initSystemConfig(context);
-        VueComponentTemplate.initComponent(VueComponentTemplate.DEFAULT_COMPONENT_PACKAGE_PATH);
+        try {
+            ApplicationContext context = SpringApplication.run(WebServiceApplicationStart.class, args);
+            ServiceStartInit.initSystemConfig(context);
+            VueComponentTemplate.initComponent(VueComponentTemplate.DEFAULT_COMPONENT_PACKAGE_PATH);
+        }catch (Throwable e){
+            logger.error("系统启动失败",e);
+        }
     }
     }
 }
 }

+ 1 - 0
eureka/src/main/java/com/java110/eureka/ConfigServerEurekaApplication.java

@@ -12,6 +12,7 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
 public class ConfigServerEurekaApplication {
 public class ConfigServerEurekaApplication {
     public static void main(String[] args) {
     public static void main(String[] args) {
         SpringApplication.run(ConfigServerEurekaApplication.class, args);
         SpringApplication.run(ConfigServerEurekaApplication.class, args);
+
     }
     }
 }
 }
 
 

+ 47 - 0
restartAllApp.sh

@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+git pull origin master
+
+mvn clean install -Dmaven.test.skip=true
+mvn package -Dmaven.test.skip=true
+
+# 刷hosts
+echo '172.17.0.2 dev.java110.com' >> /etc/hosts
+echo '172.17.0.2 dev.zk.java110.com' >> /etc/hosts
+echo '172.21.0.6 dev.redis.java110.com' >> /etc/hosts
+echo '172.17.0.2 dev.kafka.java110.com' >> /etc/hosts
+echo '172.21.0.15 dev.db.java110.com' >> /etc/hosts
+echo '172.17.0.8 api.java110.com' >> /etc/hosts
+
+if [[ -a ~/jar_deploy ]];then
+echo "存在文件jar_deploy";
+rm -rf jar_deploy
+fi;
+mkdir jar_deploy
+# 启动eureka
+cp eureka/target/eureka.jar ./jar_deploy/eureka.jar
+cp Api/target/Api.jar ./jar_deploy/Api.jar
+cp CodeService/target/CodeService.jar ./jar_deploy/CodeService.jar
+cp CommentService/target/CommentService.jar ./jar_deploy/CommentService.jar
+cp CommonService/target/CommonService.jar ./jar_deploy/CommonService.jar
+cp CommunityService/target/CommunityService.jar ./jar_deploy/CommunityService.jar
+cp FeeService/target/FeeService.jar ./jar_deploy/FeeService.jar
+cp JobService/target/JobService.jar ./jar_deploy/JobService.jar
+cp LogService/target/LogService.jar ./jar_deploy/LogService.jar
+cp OrderService/target/OrderService.jar ./jar_deploy/OrderService.jar
+cp StoreService/target/StoreService.jar ./jar_deploy/StoreService.jar
+cp UserService/target/UserService.jar ./jar_deploy/UserService.jar
+cp WebService/target/WebService.jar ./jar_deploy/WebService.jar
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/eureka.jar > eureka.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/Api.jar > Api.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/CodeService.jar > CodeService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/CommentService.jar > CommentService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/CommonService.jar > CommonService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/CommunityService.jar > CommunityService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/FeeService.jar > FeeService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/JobService.jar > JobService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/LogService.jar > LogService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/OrderService.jar > OrderService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/StoreService.jar > StoreService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/UserService.jar > UserService.log 2>&1 &
+nohup java -jar -Dspring.profiles.active=dev jar_deploy/WebService.jar > WebService.log 2>&1 &