Java tutorial
/* * Copyright 2014 Decebal Suiu * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with * the License. You may obtain a copy of the License in the LICENSE file, or at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package ro.fortsoft.pf4j.spring.demo; import org.apache.commons.lang.StringUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import ro.fortsoft.pf4j.DefaultPluginManager; import ro.fortsoft.pf4j.PluginManager; import ro.fortsoft.pf4j.spring.ExtensionsInjector; /** * @author Decebal Suiu */ @Configuration public class Boot { public static void main(String[] args) { // print logo printLogo(); // retrieves the spring application context ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Boot.class); // print greetings in System.out Greetings greetings = applicationContext.getBean(Greetings.class); greetings.printGreetings(); // stop plugins PluginManager pluginManager = applicationContext.getBean(PluginManager.class); pluginManager.stopPlugins(); } @Bean public PluginManager pluginManager() { PluginManager pluginManager = new DefaultPluginManager(); pluginManager.loadPlugins(); // start (active/resolved) the plugins pluginManager.startPlugins(); return pluginManager; } @Bean public static ExtensionsInjector extensionsInjector() { return new ExtensionsInjector(); } @Bean public Greetings greetings() { return new Greetings(); } private static void printLogo() { System.out.println(StringUtils.repeat("#", 40)); System.out.println(StringUtils.center("PF4J-SPRING", 40)); System.out.println(StringUtils.repeat("#", 40)); } }