私は、Springフレームワークをベースにしたアプリケーションを持っています。いくつかの要件を実装するために私はApplicationContext
の実装を提供しなければなりませんでした。カスタムApplicationContext実装のスプリングブートアプリケーション
spring-boot
に移動しました。起動するように強制する方法があれば、私はApplicationContext
の実装を使用していますか?
EDIT:提供コンテキストが最後から二番目の行で作成されたいくつかのコード
public class OpenPatricianSpringBootStandaloneApplication implements CommandLineRunner {
private static Logger logger = LogManager.getLogger(OpenPatricianSpringBootStandaloneApplication.class);
public static void main(String[] args) throws Exception {
SpringApplication.run(OpenPatricianSpringBootStandaloneApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
String jreVersion = (String) System.getProperties().get("java.version");
if (!jreVersion.startsWith("1.8")) {
logger.error("JRE must be of version 1.8");
System.out.println("JRE must be of version 1.8");
System.exit(1);
}
logEnvironment();
CommandLineArguments cmdHelper = new CommandLineArguments();
Options opts = cmdHelper.createCommandLineOptions();
CommandLine cmdLine = cmdHelper.parseCommandLine(opts, args);
if (cmdLine.hasOption(CommandLineArguments.HELP_OPTION)){
cmdHelper.printHelp(opts);
System.exit(0);
}
if (cmdLine.hasOption(CommandLineArguments.VERSION_OPTION)) {
System.out.println("OpenPatrician version: "+getClass().getPackage().getImplementationVersion());
System.exit(0);
}
cmdHelper.persistAsPropertyFile(cmdLine);
unpackPlugins();
ServerLauncher.initializeApplicationContext(StandaloneConfiguration.class);
OpenPaticianApplicationWindow.startClientUI(new String[0]);
}
は:
public static void initializeApplicationContext(Class clientServerContextClass) {
Preconditions.checkArgument(baseServerContext == null, "Application baseServerContext is already initialized");
baseServerContext = new DependentAnnotationConfigApplicationContext(clientServerContextClass);
logger.info("Initialize baseServerContext (" + baseServerContext.hashCode() + ") with class "+clientServerContextClass.getName());
((AbstractApplicationContext)baseServerContext).registerShutdownHook();
}
DependentAnnotationConfigApplicationContext
は、私が使用していますApplicationContext
実装です。そして、これは、スプリング・ブートがなくても、スプリング・アプリケーションが作成される方法です。
'org.springframework.boot.SpringApplication.applicationContextClass'のパブリックセッターがあります。ですから、静的な 'run(..)'メソッドを使っている間にそれを提供する方法があると思います。 – phani
@phani:['SpringApplication'](http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/SpringApplication.html)を見ても、私は何も見ませんメソッドを使用してアプリケーションコンテキストクラスを設定します。しかし、['SpringApplicationBuilder'](http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/builder/SpringApplicationBuilder.html)を使用する可能性があります。あなたは例を提供したいと思いますか? – hotzst
私はこれをあなたのような最初のタイマーにしたことはありません。方法については、http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/builder/SpringApplicationBuilder.html#contextClass-java.lang.Class- – phani