类org.springframework.context.support.LiveBeansView源码实例Demo

下面列出了怎么用org.springframework.context.support.LiveBeansView的API类实例代码及写法,或者点击链接到github查看源代码。

public static void main(String[] args) {
    originalMBeanDomain = System.getProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME);
    originalAdminEnabled = System.getProperty("spring.application.admin.enabled");

    System.clearProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME);
    System.clearProperty("spring.application.admin.enabled");
    SpringApplication.run(LauncherApplication.class, args);
}
 
@Bean
public CommandLineRunner commandLineRunner(DependencyProcessor dependencyProcessor, ResourceLoader resourceLoader) {
    return args -> {
        if (launcherProperties.getApplicationPath() == null) {
            throw new LaunchingException("application path can not be null");
        }

        if (originalMBeanDomain != null) {
            System.setProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME, originalMBeanDomain);
        }
        if (originalAdminEnabled != null) {
            System.setProperty("spring.application.admin.enabled", originalAdminEnabled);
        }

        Resource gitResource = resourceLoader.getResource("classpath:/git.properties");

        try (InputStream in = gitResource.getInputStream()) {
            Properties props = new Properties();
            props.load(in);

            props.forEach((key, value) -> {
                System.setProperty("formula.launcher." + key, (String) value);
            });
        } catch (FileNotFoundException e) {
            // do nothing
        }

        new FormulaLauncher(launcherProperties, dependencyProcessor).launch(args);
    };
}
 
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
    // 复制 BeansEndpoint#setApplicationContext(ApplicationContext) 方法实现
    if (context.getEnvironment()
            .getProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME) == null) {
        this.liveBeansView.setApplicationContext(context);
    }
}
 
@Test
public void testRestartTwice() throws Exception {

	this.context = SpringApplication.run(TestConfiguration.class,
			"--management.endpoint.restart.enabled=true", "--server.port=0",
			"--management.endpoints.web.exposure.include=restart",
			"--spring.liveBeansView.mbeanDomain=livebeans");

	RestartEndpoint endpoint = this.context.getBean(RestartEndpoint.class);
	then(this.context.getParent()).isNotNull();
	then(this.context.getParent().getParent()).isNull();
	this.context = endpoint.doRestart();

	then(this.context).isNotNull();
	then(this.context.getParent()).isNotNull();
	then(this.context.getParent().getParent()).isNull();

	RestartEndpoint next = this.context.getBean(RestartEndpoint.class);
	then(next).isSameAs(endpoint);
	this.context = next.doRestart();

	then(this.context).isNotNull();
	then(this.context.getParent()).isNotNull();
	then(this.context.getParent().getParent()).isNull();

	LiveBeansView beans = new LiveBeansView();
	String json = beans.getSnapshotAsJson();
	then(json).containsOnlyOnce("parent\": \"bootstrap");
	then(json).containsOnlyOnce("parent\": null");
}
 
protected LiveBeansView buildLiveBeansView() {
	return new ServletContextLiveBeansView(getServletContext());
}
 
protected LiveBeansView buildLiveBeansView() {
	return new ServletContextLiveBeansView(getServletContext());
}
 
源代码7 项目: lams   文件: LiveBeansViewServlet.java
protected LiveBeansView buildLiveBeansView() {
	return new ServletContextLiveBeansView(getServletContext());
}
 
protected LiveBeansView buildLiveBeansView() {
	return new ServletContextLiveBeansView(getServletContext());
}
 
 类方法
 同包方法