/** * Creates and initializes Petite container. * It will be auto-magically configured by scanning the classpath. */ @Override public void start() { initLogger(); log.info("PETITE start ----------"); petiteContainer = createPetiteContainer(); if (externalsCache) { petiteContainer.setExternalsCache(TypeCache.createDefault()); } log.info("Web application? " + isWebApplication); if (!isWebApplication) { // make session scope to act as singleton scope // if this is not a web application (and http session is not available). petiteContainer.registerScope(SessionScope.class, new SingletonScope(petiteContainer)); } // load parameters from properties files petiteContainer.defineParameters(joyPropsSupplier.get().getProps()); // automagic configuration if (autoConfiguration) { final AutomagicPetiteConfigurator automagicPetiteConfigurator = new AutomagicPetiteConfigurator(petiteContainer); automagicPetiteConfigurator.registerAsConsumer(joyScannerSupplier.get().getClassScanner()); } petiteContainerConsumers.accept(this.petiteContainer); log.info("PETITE OK!"); }
@BeforeEach void setupPetiteContainer() { final PetiteConfig petiteConfig = PetiteHelper.createPetiteConfig(); final ProxyProxetta proxyProxetta = PetiteHelper.createProxyProxetta(); petiteContainer = new ProxettaAwarePetiteContainer(proxyProxetta, petiteConfig); final AutomagicPetiteConfigurator petiteConfigurator = new AutomagicPetiteConfigurator(petiteContainer); petiteConfigurator.withScanner(scanner -> scanner.includeEntries(this.getClass().getPackage().getName() + ".*")); petiteConfigurator.configure(); }
/** * Configures {@link jodd.petite.PetiteContainer} with specified class path. */ public void configure() { long elapsed = System.currentTimeMillis(); final ClassScanner classScanner = new ClassScanner(); classScanner.detectEntriesMode(true); classScanner.scanDefaultClasspath(); classScannerConsumers.accept(classScanner); registerAsConsumer(classScanner); try { classScanner.start(); } catch (Exception ex) { throw new PetiteException("Scan classpath error", ex); } elapsed = System.currentTimeMillis() - elapsed; log.info("Petite configured in " + elapsed + " ms. Total beans: " + container.beansCount()); }
/** * Configures {@link jodd.petite.PetiteContainer} with specified class path. */ public void configure() { long elapsed = System.currentTimeMillis(); final ClassScanner classScanner = new ClassScanner(); classScanner.detectEntriesMode(true); classScanner.scanDefaultClasspath(); classScannerConsumers.accept(classScanner); registerAsConsumer(classScanner); try { classScanner.start(); } catch (Exception ex) { throw new PetiteException("Scan classpath error", ex); } elapsed = System.currentTimeMillis() - elapsed; log.info("Petite configured in " + elapsed + " ms. Total beans: " + container.beansCount()); }
/** * Creates and initializes Petite container. * It will be auto-magically configured by scanning the classpath. */ @Override public void start() { initLogger(); log.info("PETITE start ----------"); petiteContainer = createPetiteContainer(); if (externalsCache) { petiteContainer.setExternalsCache(TypeCache.createDefault()); } log.info("Web application? " + isWebApplication); if (!isWebApplication) { // make session scope to act as singleton scope // if this is not a web application (and http session is not available). petiteContainer.registerScope(SessionScope.class, new SingletonScope(petiteContainer)); } // load parameters from properties files petiteContainer.defineParameters(joyPropsSupplier.get().getProps()); // automagic configuration if (autoConfiguration) { final AutomagicPetiteConfigurator automagicPetiteConfigurator = new AutomagicPetiteConfigurator(petiteContainer); automagicPetiteConfigurator.registerAsConsumer(joyScannerSupplier.get().getClassScanner()); } petiteContainerConsumers.accept(this.petiteContainer); log.info("PETITE OK!"); }
@Test @DisabledOnJava(value = 9, description = "Automagic configuration only works with MR-JAR jars as they don't work in exploded mode.") void testContainer() { PetiteContainer pc = new PetiteContainer(); AutomagicPetiteConfigurator petiteConfigurator = new AutomagicPetiteConfigurator(pc); petiteConfigurator.withScanner(classScanner -> classScanner .excludeAllEntries(true) .includeEntries("jodd.petite.fixtures.*") .excludeEntries("jodd.petite.fixtures.data.*", "jodd.petite.fixtures.tst3.*", "jodd.petite.fixtures.tst.Ses") .excludeEntries( "jodd.petite.fixtures.data.*", "jodd.petite.fixtures.tst6.*", "jodd.petite.fixtures.tst.Ses", "*Public*", "*Secret*", "*$*", "jodd.petite.proxy.*", "jodd.petite.fixtures.rainbow.*")); petiteConfigurator.configure(); assertEquals(1, pc.beansCount()); assertEquals(1, pc.scopesCount()); assertEquals(0, Foo.instanceCounter); Foo foo = pc.getBean("foo"); assertNotNull(foo); }