• 大小: 82KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-19
  • 语言: Java
  • 标签: springboot  业务插件  

资源简介

springboot 插件热加载外部class或者jar,实现业务不停机加载。

资源截图

代码片段和文件信息

package com.zzw.beandymanicload;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletContext;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


@RestController
@SpringBootApplication
@ComponentScan(basePackages = {“com“})
public class BeandymanicloadApplication {

@Autowired
public GetStringBean getStringBean;

// @Autowired
// private ServletContext servletContext;
//
// @RequestMapping(“/hello“)
// public String helloword(){
// servletContext.setAttribute(“aaa““tttttttttttttttttt“);
// TestCache.aaa.put(“bbb““cccccccccccccc“);
// return getStringBean.getString();
// }

@RequestMapping(“/beanLoad“)
public String beanLoad(){
ApplicationContext applicationContext = CommonContextUtils.getApplicationContext();
ConfigurableApplicationContext context = (ConfigurableApplicationContext)applicationContext;
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)context.getBeanFactory();
ClassLoader beanClassLoader = beanFactory.getBeanClassLoader();
Class aClass = ClassUtil.LoadJar(“D:/classtest“beanClassLoader).get(0);
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(aClass);
beanFactory.registerBeanDefinition(aClass.getName()beanDefinitionBuilder.getRawBeanDefinition());
object aaa = (applicationContext.getBean(aClass.getName()));
Method m = null;
Method m2 = null;
try {
m2 = aClass.getMethod(“setApplicationContext“ ApplicationContext.class);
m = aClass.getMethod(“getString“ null);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
object ret = null;
try {
m2.invoke(aaaapplicationContext);
ret = m.invoke(aaa null);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return ret.toString();
}
public static void main(String[] args) {
SpringApplication.run(BeandymanicloadApplication.class args);
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        249  2018-02-27 13:17  beandymanicload\.gitignore

     文件        595  2018-03-16 09:53  beandymanicload\.idea\artifacts\getString.xml

     文件        642  2018-02-27 13:18  beandymanicload\.idea\compiler.xml

     文件      22942  2018-03-07 16:28  beandymanicload\.idea\dbnavigator.xml

     文件         94  2018-02-27 13:18  beandymanicload\.idea\dictionaries\zhengwei_zhou.xml

     文件        191  2018-02-27 13:18  beandymanicload\.idea\encodings.xml

     文件        575  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__ch_qos_logback_logback_classic_1_1_11.xml

     文件        554  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__ch_qos_logback_logback_core_1_1_11.xml

     文件        522  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__com_fasterxml_classmate_1_3_4.xml

     文件        644  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml

     文件        602  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml

     文件        630  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml

     文件        546  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__com_jayway_jsonpath_json_path_2_2_0.xml

     文件        700  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml

     文件        611  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__javax_validation_validation_api_1_1_0_Final.xml

     文件        455  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__junit_junit_4_12.xml

     文件        542  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__net_minidev_accessors_smart_1_1.xml

     文件        521  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__net_minidev_json_smart_2_2_1.xml

     文件        625  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_27.xml

     文件        611  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_27.xml

     文件        660  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_27.xml

     文件        636  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_apache_tomcat_tomcat_annotations_api_8_5_27.xml

     文件        535  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_assertj_assertj_core_2_6_0.xml

     文件        532  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_hamcrest_hamcrest_core_1_3.xml

     文件        553  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_hamcrest_hamcrest_library_1_3.xml

     文件        634  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_hibernate_hibernate_validator_5_3_6_Final.xml

     文件        608  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_jboss_logging_jboss_logging_3_3_1_Final.xml

     文件        549  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_mockito_mockito_core_1_10_19.xml

     文件        508  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_objenesis_objenesis_2_1.xml

     文件        472  2018-02-27 13:18  beandymanicload\.idea\libraries\Maven__org_ow2_asm_asm_5_0_3.xml

............此处省略74个文件信息

评论

共有 条评论