private void run(String[] args) { // checkSystemProperties(zkUrl); SpringApplication app = new SpringApplication(Application.class); app.setShowBanner(false); app.run(args); }
@Test public void testDefaultSettings() throws Exception { assertEquals(0, SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class))); String output = this.outputCapture.toString(); assertTrue( "Wrong output: " + output, output.contains("completed with the following parameters")); }
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { SpringApplicationBuilder builder = new SpringApplicationBuilder(); builder.main(getClass()); ApplicationContext parent = getExistingRootWebApplicationContext(servletContext); if (parent != null) { this.logger.info("Root context already created (using as parent)."); servletContext.setAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null); builder.initializers(new ParentContextApplicationContextInitializer(parent)); } builder.initializers(new ServletContextApplicationContextInitializer(servletContext)); builder.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); builder = configure(builder); SpringApplication application = builder.build(); if (application.getSources().isEmpty() && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) { application.getSources().add(getClass()); } Assert.state( application.getSources().size() > 0, "No SpringApplication sources have been defined. Either override the " + "configure method or add an @Configuration annotation"); // Ensure error pages are registered application.getSources().add(ErrorPageFilter.class); return run(application); }
@BeforeClass public static void startUp() throws InterruptedException, IOException { if (applicationContext == null) { if (System.getProperty(SHUTDOWN_AFTER_RUN) != null) { shutdownAfterRun = Boolean.getBoolean(SHUTDOWN_AFTER_RUN); } SpringApplication application = new SpringApplicationBuilder( AdminApplication.class, AdminConfiguration.class, TestConfig.class) .build(); applicationContext = application.run( String.format("--server.port=%s", adminPort), "--security.basic.enabled=false", "--spring.main.show_banner=false", "--spring.cloud.config.enabled=false"); } JLineShellComponent shell = new Bootstrap(new String[] {"--port", String.valueOf(adminPort)}).getJLineShellComponent(); if (!shell.isRunning()) { shell.start(); } dataFlowShell = new DataFlowShell(shell); }
public static void main(String[] args) { SpringApplication application = new SpringApplication( TransformerMessageEndpointMain.class, TransformerMessageEndpointConfiguration.class); application.setApplicationContextClass(AnnotationConfigApplicationContext.class); application.run(args); }
public static void main(String[] args) { SpringApplication application = new SpringApplication(PrivilegeCommonMain.class); Set<Object> sourcesSet = new HashSet<Object>(); // sourcesSet.add("classpath:spring/applicationContext.xml"); sourcesSet.add("classpath:spring/*.xml"); application.setSources(sourcesSet); application.run(args); }
public static void main(String... args) { ApplicationContext appContext = SpringApplication.run(Application.class, args); ContactService contactService = appContext.getBean(ContactService.class); System.out.println(contactService.ping()); SpringApplication.exit(appContext); }
@Test public void testDefaultProfile() { SpringApplication app = new SpringApplication(AdminApplication.class); ConfigurableApplicationContext context = app.run(new String[] {"--server.port=0"}); assertThat(context.containsBean("processModuleDeployer"), is(true)); assertThat(context.getBean("processModuleDeployer"), instanceOf(LocalModuleDeployer.class)); context.close(); }
@Test public void profileSubDocumentInSameProfileSpecificFile() throws Exception { // gh-340 SpringApplication application = new SpringApplication(Config.class); application.setWebEnvironment(false); this.context = application.run("--spring.profiles.active=activeprofilewithsubdoc"); String property = this.context.getEnvironment().getProperty("foobar"); assertThat(property, equalTo("baz")); }
public static void main(String[] args) { if (!VersionedApplication.versionedApplication().showVersionInfo(args)) { if (args.length == 0) { SpringApplication.run(JaguarApplication.class); } else { SpringApplication.run(JaguarApplication.class, args); } } }
@Test public void propertySourceAnnotationWithName() throws Exception { SpringApplication application = new SpringApplication(WithPropertySourceAndName.class); application.setWebEnvironment(false); ConfigurableApplicationContext context = application.run(); String property = context.getEnvironment().getProperty("the.property"); assertThat(property, equalTo("fromspecificlocation")); assertThat(context.getEnvironment(), containsPropertySource("foo")); context.close(); }
/** Main method, used to run the application. */ public static void main(String[] args) { SpringApplication app = new SpringApplication(Application.class); app.setShowBanner(false); SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args); // Check if the selected profile has been set as argument. // if not the development profile will be added addDefaultProfile(app, source); app.run(args); }
@Test public void activateProfileFromProfileSpecificProperties() throws Exception { SpringApplication application = new SpringApplication(Config.class); application.setWebEnvironment(false); this.context = application.run("--spring.profiles.active=includeprofile"); assertThat(this.context.getEnvironment(), acceptsProfiles("includeprofile")); assertThat(this.context.getEnvironment(), acceptsProfiles("specific")); assertThat(this.context.getEnvironment(), acceptsProfiles("morespecific")); assertThat(this.context.getEnvironment(), acceptsProfiles("yetmorespecific")); assertThat(this.context.getEnvironment(), not(acceptsProfiles("missing"))); }
@Test public void replacesServiceLocator() throws Exception { SpringApplication application = new SpringApplication(Conf.class); application.setWebEnvironment(false); this.context = application.run(); ServiceLocator instance = ServiceLocator.getInstance(); Field field = ReflectionUtils.findField(ServiceLocator.class, "classResolver"); field.setAccessible(true); Object resolver = field.get(instance); assertThat(resolver).isInstanceOf(SpringPackageScanClassResolver.class); }
@Test public void propertySourceAnnotationAndNonActiveProfile() throws Exception { SpringApplication application = new SpringApplication(WithPropertySourceAndProfile.class); application.setWebEnvironment(false); ConfigurableApplicationContext context = application.run(); String property = context.getEnvironment().getProperty("my.property"); assertThat(property, equalTo("fromapplicationproperties")); assertThat( context.getEnvironment(), not(containsPropertySource("classpath:" + "/enableprofile-myprofile.properties"))); context.close(); }
/** Main method, used to run the application. */ public static void main(String[] args) throws UnknownHostException { SpringApplication app = new SpringApplication(Application.class); SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args); addDefaultProfile(app, source); Environment env = app.run(args).getEnvironment(); log.info( "Access URLs:\n----------------------------------------------------------\n\t" + "Local: \t\thttp://127.0.0.1:{}\n\t" + "External: \thttp://{}:{}\n----------------------------------------------------------", env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")); }
public static void main(String[] args) throws Exception { log.info("application start..."); ApplicationContext ctx = SpringApplication.run(ApplicationConfig.class, args); String[] defName = ctx.getBeanDefinitionNames(); for (String name : defName) { log.info("beanDefinitionName={}", name); } Busboy busboy = ctx.getBean(Busboy.class); busboy.test(); SpringApplication.exit(ctx); }
@Test public void propertySourceAnnotationMultipleLocations() throws Exception { SpringApplication application = new SpringApplication(WithPropertySourceMultipleLocations.class); application.setWebEnvironment(false); ConfigurableApplicationContext context = application.run(); String property = context.getEnvironment().getProperty("the.property"); assertThat(property, equalTo("frommorepropertiesfile")); assertThat( context.getEnvironment(), containsPropertySource("class path resource " + "[specificlocation.properties]")); context.close(); }
public static void main(String[] args) throws UnknownHostException { SpringApplication app = new SpringApplication(Application.class); app.setShowBanner(false); Environment env = app.run(args).getEnvironment(); log.info( "Access URLs:\n----------------------------------------------------------\n\t" + "Local: \t\thttp://127.0.0.1:{}\n\t" + "External: \thttp://{}:{}\n----------------------------------------------------------", env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")); }
@Test public void propertySourceAnnotationWithPlaceholder() throws Exception { EnvironmentTestUtils.addEnvironment(this.environment, "source.location:specificlocation"); SpringApplication application = new SpringApplication(WithPropertySourcePlaceholders.class); application.setEnvironment(this.environment); application.setWebEnvironment(false); ConfigurableApplicationContext context = application.run(); String property = context.getEnvironment().getProperty("the.property"); assertThat(property, equalTo("fromspecificlocation")); assertThat( context.getEnvironment(), containsPropertySource("class path resource " + "[specificlocation.properties]")); context.close(); }
/** * Main method, used to run the application. * * @param args the command line arguments * @throws UnknownHostException if the local host name could not be resolved into an address */ public static void main(String[] args) throws UnknownHostException { SpringApplication app = new SpringApplication(JhipsterNoCacheSampleApplicationApp.class); DefaultProfileUtil.addDefaultProfile(app); Environment env = app.run(args).getEnvironment(); log.info( "\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://localhost:{}\n\t" + "External: \thttp://{}:{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")); }
public static void main(String[] args) throws InterruptedException { SpringApplication app = new SpringApplication(App.class); app.setWebEnvironment(false); ConfigurableApplicationContext context = app.run(args); try { int orders = 100; placeOrders(orders, context); checkOrdersInStorage(orders, context); completeBatch(context); } finally { Try.apply(() -> context.getBean(ActorSystem.class)).foreach(ActorSystem::terminate); } }
@Test public void propertySourceAnnotationInProfile() throws Exception { SpringApplication application = new SpringApplication(WithPropertySourceInProfile.class); application.setWebEnvironment(false); ConfigurableApplicationContext context = application.run("--spring.profiles.active=myprofile"); String property = context.getEnvironment().getProperty("the.property"); assertThat(property, equalTo("frompropertiesfile")); assertThat( context.getEnvironment(), containsPropertySource("class path resource " + "[enableprofile.properties]")); assertThat( context.getEnvironment(), not(containsPropertySource("classpath:/" + "enableprofile-myprofile.properties"))); context.close(); }
/** * Enforce mutual exclusivity and implicit activation of profiles as described in {@link * SaganProfiles}. */ @Override protected void configureProfiles(ConfigurableEnvironment environment, String[] args) { super.configureProfiles(environment, args); boolean stagingActive = environment.acceptsProfiles(STAGING); boolean productionActive = environment.acceptsProfiles(PRODUCTION); if (stagingActive && productionActive) { throw new IllegalStateException( format( "Only one of the following profiles may be specified: [%s]", arrayToCommaDelimitedString(new String[] {STAGING, PRODUCTION}))); } if (stagingActive || productionActive) { logger.info( format( "Activating '%s' profile because one of '%s' or '%s' profiles have been specified.", CLOUDFOUNDRY, STAGING, PRODUCTION)); environment.addActiveProfile(CLOUDFOUNDRY); } else { logger.info( "The default 'standalone' profile is active because no other profiles have been specified."); environment.addActiveProfile(STANDALONE); } }
/** * Run the application using Spring Boot and an embedded servlet engine. * * @param args Program arguments - ignored. */ public static void main(String[] args) { // Tell server to look for accounts-server.properties or // accounts-server.yml System.setProperty("spring.config.name", "training-server"); SpringApplication.run(TrainingServer.class, args); }
public static void main(String[] args) throws InterruptedException { log.info("-----------Starting Redis hash testing-----------"); ApplicationContext ctx = SpringApplication.run(HashTest.class, args); RedisConnectionFactory connectionFactory = ctx.getBean(RedisConnectionFactory.class); userTemplate = new RedisTemplate<>(); userTemplate.setConnectionFactory(connectionFactory); userTemplate.setKeySerializer(userTemplate.getStringSerializer()); userTemplate.setHashKeySerializer(userTemplate.getStringSerializer()); userTemplate.setHashValueSerializer(new JacksonJsonRedisSerializer<UserInfo>(UserInfo.class)); userTemplate.afterPropertiesSet(); doubleTemplate = new RedisTemplate<>(); doubleTemplate.setConnectionFactory(connectionFactory); doubleTemplate.setKeySerializer(doubleTemplate.getStringSerializer()); doubleTemplate.setHashKeySerializer(doubleTemplate.getStringSerializer()); doubleTemplate.setHashValueSerializer(doubleTemplate.getDefaultSerializer()); doubleTemplate.afterPropertiesSet(); longTemplate = new RedisTemplate<>(); longTemplate.setConnectionFactory(connectionFactory); longTemplate.setKeySerializer(longTemplate.getStringSerializer()); longTemplate.setHashKeySerializer(longTemplate.getStringSerializer()); longTemplate.setHashValueSerializer(new LongSerializer()); longTemplate.afterPropertiesSet(); HashTest hashTest = ctx.getBean(HashTest.class); // hashTest.insert(); // hashTest.batchInsert(); // hashTest.insertIfAbsent(); // hashTest.findAll(); // hashTest.findOne(); // hashTest.findAllKeys(); // hashTest.incrementDouble(); hashTest.incrementLong(); }
void start(String[] args) { System.setProperty("java.awt.headless", "false"); ParkingMeterRunner.arguments = args; LOG.info("Init application startup. Arguments: " + Arrays.toString(args)); SpringApplication app; ConfigurableApplicationContext context; // Start Spring app = getSpringApplication(); context = app.run(args); context.getBean(ViewController.class).start(); }
/** * 启动Tesseract * * @param args 启动参数 * @throws RegisterFunctionException */ public static void main(String[] args) throws RegisterFunctionException { ConfigurableApplicationContext context = SpringApplication.run(TesseractApplication.class); ApplicationContextHelper.setContext(context); RegisterFunction.register("rRate", RelativeRate.class); RegisterFunction.register("sRate", SimilitudeRate.class); StoreManager.addUdfDeSerializerSetting( new Function<Object[], Object>() { @SuppressWarnings({"unchecked", "rawtypes"}) @Override public Object apply(Object[] t) { try { return AnswerCoreConstant.GSON.fromJson(t[0].toString(), (Class) t[1]); } catch (Exception e) { return null; } } }); StoreManager.addUdfSerializerSetting( new Function<Object[], Object>() { public Object apply(Object[] t) { return AnswerCoreConstant.GSON.toJson(t[0]); } }); // CacheManager cacheManager = (CacheManager) context.getBean("redisCacheManager"); // // cacheManager.getCache("test").put("key", "val"); }
/** * Main class initializes the Spring Application Context and populates seed data using {@link * SeedDataService}. * * @param args Not used. */ public static void main(String[] args) { Map<String, Object> props = new HashMap<String, Object>(); props.put("redisPort", SocketUtils.findAvailableTcpPort()); SpringApplication app = new SpringApplication(MainApp.class); app.setDefaultProperties(props); ConfigurableApplicationContext context = app.run(args); MapPropertySource propertySource = new MapPropertySource("ports", props); context.getEnvironment().getPropertySources().addFirst(propertySource); SeedDataService seedDataService = context.getBean(SeedDataService.class); seedDataService.populateSeedData(); }
/** If no profile has been configured, set by default the "dev" profile. */ private static void addDefaultProfile( SpringApplication app, SimpleCommandLinePropertySource source) { if (!source.containsProperty("spring.profiles.active") && !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) { app.setAdditionalProfiles("dev"); } }