【发布时间】:2017-09-16 06:24:37
【问题描述】:
我配置了
<distributable/>
在 web.xml 中。现在我需要检查 Web 应用程序是否可分发。
我该怎么做?
【问题讨论】:
标签: java spring-mvc servlets spring-boot cluster-computing
我配置了
<distributable/>
在 web.xml 中。现在我需要检查 Web 应用程序是否可分发。
我该怎么做?
【问题讨论】:
标签: java spring-mvc servlets spring-boot cluster-computing
您可以从 Tomcat context 获取此信息。您可以将嵌入式 Tomcat 容器定义为 @Bean 并从那里获取。
import org.apache.catalina.Context;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Application {
private static boolean distributable;
public static boolean getDistributable() {
return distributable;
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
Application.distributable = context.getDistributable();
System.out.println("distributable is :"+distributable);
}
};
}
}
您可能需要在工厂中以编程方式 setDistributable(true/false) 才能使其正常工作。
【讨论】: