All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.dreampie.common.spring.SpringPlugin Maven / Gradle / Ivy

There is a newer version: 1.3.0.RELEASE
Show newest version
package cn.dreampie.common.spring;

import cn.dreampie.common.Plugin;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Dreampie
 * @date 2015-10-08
 * @what
 */
public class SpringPlugin implements Plugin {

  private String[] configFiles;
  private Class[] configClasses;
  private ConfigurableApplicationContext context;

  /**
   * Use configuration under the path of WebRoot/WEB-INF.
   */
  public SpringPlugin() {
    this.configFiles = new String[]{"classpath:applicationContext.xml"};
  }

  public SpringPlugin(String... configFiles) {
    this.configFiles = configFiles;
  }

  public SpringPlugin(ConfigurableApplicationContext context) {
    this.context = context;
  }

  public SpringPlugin(Class... configClasses) {
    this.configClasses = configClasses;
  }

  public boolean start() {
    if (this.context == null) {
      if (configFiles == null) {
        this.context = new AnnotationConfigApplicationContext(configClasses);
      } else {
        this.context = new ClassPathXmlApplicationContext(configFiles);
      }
    }
    SpringBuilder.setContext(context);
    return true;
  }

  public boolean stop() {
    SpringBuilder.removeContext();
    return true;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy