Exemplo n.º 1
0
  /**
   * Creates and initializes Petite container. It will be auto-magically configured by scanning the
   * classpath. Also, all 'app*.prop*' will be loaded and values will be injected in the matched
   * beans. At the end it registers this instance of core into the container.
   */
  protected void startPetite() {
    log.info("petite initialization");
    petite = createPetiteContainer();

    log.info("app in web: " + Boolean.valueOf(isWebApplication));
    if (isWebApplication == false) {
      // make session scope to act as singleton scope
      // if this is not a web application (and http session is not available).
      petite.registerScope(SessionScope.class, new SingletonScope());
    }

    // load parameters from properties files
    petite.defineParameters(appProps);

    // adds a scanner bean, so it can be immediately configured from props
    petite.addBean(PETITE_SCAN, appScanner);

    // automagic configuration
    registerPetiteContainerBeans(petite);

    // add AppCore instance to Petite
    petite.addBean(PETITE_CORE, this);

    petite.addBean(PETITE_PROPS, appProps);
  }
  @Before
  public void init() {

    petite = new PetiteContainer();

    // load parameters
    Props appProps = new Props();
    PropsUtil.loadFromClasspath(appProps, "/props.props");
    petite.defineParameters(appProps);

    // add appCore to Petite (and resolve parameters)
    AutomagicPetiteConfigurator pcfg = new AutomagicPetiteConfigurator();
    pcfg.setIncludedEntries(this.getClass().getPackage().getName() + ".*");
    pcfg.configure(petite);
  }