org.springframework.boot.SpringApplication#setDefaultProperties ( )源码实例Demo

下面列出了org.springframework.boot.SpringApplication#setDefaultProperties ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Tests a Logback-access configuration exception in the case where the main configuration file is invalid.
 */
@Test
public void logbackAccessConfigurationExceptionWhereMainConfigurationFileIsInvalid() {

    Map<String, Object> properties = new HashMap<>();
    properties.put("server.port", findAvailableTcpPort());

    SpringApplication application = new SpringApplication(contextConfiguration);
    application.setDefaultProperties(properties);
    Throwable throwable = catchThrowable(application::run);
    Optional<LogbackAccessConfigurationException> exc = findLogbackAccessConfigurationException(throwable);

    assertThat(exc).hasValueSatisfying(value ->
            assertThat(value)
                    .hasMessageStartingWith("Could not configure Logback-access:")
                    .hasMessageContaining("config=[classpath:logback-access.xml]")
                    .hasCauseInstanceOf(JoranException.class)
    );

}
 
/**
 * test sofa.middleware.log.console.level config
 */
@Test
public void testGlobalConsoleLevelConfig() {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(Constants.SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH, "true");
    properties.put(Constants.SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_LEVEL, "debug");
    SpringApplication springApplication = new SpringApplication(EmptyConfig.class);
    springApplication.setDefaultProperties(properties);
    springApplication.run(new String[] {});
    logger.info("global space console");
    logger.debug("global space console debug");
    Assert.assertTrue(outContent.toString().contains("global space console"));
    Assert.assertTrue(outContent.toString().contains("global space console debug"));
    LogEnvUtils.processGlobalSystemLogProperties().remove(
        Constants.SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH);
    LogEnvUtils.processGlobalSystemLogProperties().remove(
        Constants.SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_LEVEL);
}
 
/**
 * test sofa.middleware.log.console.logback.pattern config
 */
@Test
public void testLogbackLogConsolePattern() {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(Constants.SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH, "true");
    properties.put(Constants.SOFA_MIDDLEWARE_LOG_CONSOLE_LOGBACK_PATTERN,
        "logback-test-console-pattern"
                + Constants.SOFA_MIDDLEWARE_LOG_CONSOLE_LOGBACK_PATTERN_DEFAULT);
    SpringApplication springApplication = new SpringApplication(EmptyConfig.class);
    springApplication.setDefaultProperties(properties);
    springApplication.run(new String[] {});
    logger.info("global space console");
    Assert.assertTrue(outContent.toString().contains("logback-test-console-pattern"));
    LogEnvUtils.processGlobalSystemLogProperties().remove(
        Constants.SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH);
    LogEnvUtils.processGlobalSystemLogProperties().remove(
        Constants.SOFA_MIDDLEWARE_LOG_CONSOLE_LOGBACK_PATTERN);
}
 
源代码4 项目: TeamDojo   文件: DefaultProfileUtil.java
/**
 * Set a default to use when no profile is configured.
 *
 * @param app the Spring application
 */
public static void addDefaultProfile(SpringApplication app) {
    Map<String, Object> defProperties = new HashMap<>();
    /*
     * The default profile to use when no other profiles are defined
     * This cannot be set in the <code>application.yml</code> file.
     * See https://github.com/spring-projects/spring-boot/issues/1219
     */
    defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
    app.setDefaultProperties(defProperties);
}
 
源代码5 项目: sdn-rx   文件: Benchmarks.java
@Setup
public void setup() {
	Map<String, Object> neo4jConfig = prepareNeo4j();

	SpringApplication springApplication = new SpringApplication();
	springApplication.addPrimarySources(Collections.singletonList(Application.class));
	springApplication.setLazyInitialization(true);
	springApplication.setDefaultProperties(neo4jConfig);

	this.applicationContext = springApplication.run();
	this.movieRepository = applicationContext.getBean(MovieRepository.class);
	this.driver = applicationContext.getBean(Driver.class);
}
 
源代码6 项目: sdn-rx   文件: Benchmarks.java
@Setup
public void setup() {
	Map<String, Object> neo4jConfig = prepareNeo4j();

	SpringApplication springApplication = new SpringApplication();
	springApplication.addPrimarySources(Collections.singletonList(Application.class));
	springApplication.setLazyInitialization(true);
	springApplication.setDefaultProperties(neo4jConfig);

	this.applicationContext = springApplication.run();
	this.movieRepository = applicationContext.getBean(MovieRepository.class);
	this.driver = applicationContext.getBean(Driver.class);
}
 
public static void main(String[] args) {
    final SpringApplication springApplication =
        new SpringApplication(Application.class);
    // ir is being added here for LOCAL run ONLY , spring profiles should be be run time parameters when run spring boot jar
    springApplication.setDefaultProperties(Collections.singletonMap("spring.profiles.default","LOCAL"));
    springApplication.addListeners(new ApplicationPidFileWriter());
    springApplication.run(args);
}
 
源代码8 项目: JavaQuarkBBS   文件: ChatApplication.java
public static void main(String[] args) throws IOException {
    Properties properties = new Properties();
    InputStream in = ChatApplication.class.getClassLoader().getResourceAsStream("chat.properties");
    properties.load(in);
    SpringApplication app = new SpringApplication(ChatApplication.class);
    app.setDefaultProperties(properties);
    app.run(args);
}
 
源代码9 项目: 21-points   文件: DefaultProfileUtil.java
/**
 * Set a default to use when no profile is configured.
 *
 * @param app the Spring application
 */
public static void addDefaultProfile(SpringApplication app) {
    Map<String, Object> defProperties = new HashMap<>();
    /*
    * The default profile to use when no other profiles are defined
    * This cannot be set in the <code>application.yml</code> file.
    * See https://github.com/spring-projects/spring-boot/issues/1219
    */
    defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
    app.setDefaultProperties(defProperties);
}
 
源代码10 项目: android-uiconductor   文件: Application.java
public static void main(String[] args) {
  // To initialized the logger for spring.
  // Have to init here, otherwise, in other class we won't able to get logger.
  UicdCoreDelegator.getInstance();
  if (loadFromConfigFile()) {
    return;
  }
  SpringApplication application = new SpringApplication(Application.class);
  application.setDefaultProperties(DataSourceConfig.getDBProperties());
  Application.context = application.run(args);
  Application.args = args;
}
 
源代码11 项目: ehcache3-samples   文件: DefaultProfileUtil.java
/**
 * Set a default to use when no profile is configured.
 *
 * @param app the Spring application
 */
public static void addDefaultProfile(SpringApplication app) {
    Map<String, Object> defProperties = new HashMap<>();
    /*
    * The default profile to use when no other profiles are defined
    * This cannot be set in the <code>application.yml</code> file.
    * See https://github.com/spring-projects/spring-boot/issues/1219
    */
    defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
    app.setDefaultProperties(defProperties);
}
 
源代码12 项目: clamav-rest   文件: Application.java
public static void main(String[] args) {
  SpringApplication app = new SpringApplication(Application.class);
  Map<String, Object> defaults = new HashMap<String, Object>();
  defaults.put("clamd.host", "192.168.50.72");
  defaults.put("clamd.port", 3310);
  defaults.put("clamd.timeout", 500);
  defaults.put("clamd.maxfilesize", "20000KB");
  defaults.put("clamd.maxrequestsize", "20000KB");
  app.setDefaultProperties(defaults);
  app.run(args);
}
 
/**
 * Set a default to use when no profile is configured.
 *
 * @param app the Spring application
 */
public static void addDefaultProfile(SpringApplication app) {
    Map<String, Object> defProperties =  new HashMap<>();
    /*
    * The default profile to use when no other profiles are defined
    * This cannot be set in the <code>application.yml</code> file.
    * See https://github.com/spring-projects/spring-boot/issues/1219
    */
    defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
    app.setDefaultProperties(defProperties);
}
 
public static void main(final String[] args) {
    final SpringApplication application = new SpringApplication(AddressMigratorApp2.class);
    final Properties properties = new Properties();
    properties.putIfAbsent("server.port", 9010);
    application.setDefaultProperties(properties);
    application.run(args);
}
 
@Test
public void testDisableBizStateEndpoint() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("management.endpoint.bizState.enabled", "false");
    SpringApplication springApplication = new SpringApplication(EmptyConfiguration.class);
    springApplication.setDefaultProperties(properties);
    ConfigurableApplicationContext applicationContext = springApplication.run(new String[] {});
    Assert.assertFalse(applicationContext.containsBean("introspectBizEndpoint"));
    applicationContext.close();
}
 
源代码16 项目: JavaQuarkBBS   文件: PortalApplication.java
public static void main(String[] args) throws IOException {
    //更改properties配置文件名称,避免依赖冲突
    Properties properties = new Properties();
    InputStream in = PortalApplication.class.getClassLoader().getResourceAsStream("portal.properties");
    properties.load(in);
    SpringApplication app = new SpringApplication(PortalApplication.class);
    app.setDefaultProperties(properties);
    app.run(args);
}
 
/**
 * Set a default to use when no profile is configured.
 *
 * @param app the Spring application
 */
public static void addDefaultProfile(SpringApplication app) {
    Map<String, Object> defProperties = new HashMap<>();
    /*
    * The default profile to use when no other profiles are defined
    * This cannot be set in the <code>application.yml</code> file.
    * See https://github.com/spring-projects/spring-boot/issues/1219
    */
    defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
    app.setDefaultProperties(defProperties);
}
 
源代码18 项目: cubeai   文件: DefaultProfileUtil.java
/**
 * Set a default to use when no profile is configured.
 *
 * @param app the Spring application
 */
public static void addDefaultProfile(SpringApplication app) {
    Map<String, Object> defProperties = new HashMap<>();
    /*
    * The default profile to use when no other profiles are defined
    * This cannot be set in the <code>application.yml</code> file.
    * See https://github.com/spring-projects/spring-boot/issues/1219
    */
    defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
    app.setDefaultProperties(defProperties);
}
 
源代码19 项目: cubeai   文件: DefaultProfileUtil.java
/**
 * Set a default to use when no profile is configured.
 *
 * @param app the Spring application
 */
public static void addDefaultProfile(SpringApplication app) {
    Map<String, Object> defProperties = new HashMap<>();
    /*
    * The default profile to use when no other profiles are defined
    * This cannot be set in the <code>application.yml</code> file.
    * See https://github.com/spring-projects/spring-boot/issues/1219
    */
    defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
    app.setDefaultProperties(defProperties);
}
 
源代码20 项目: kurento-java   文件: JsonRpcConnectorBaseTest.java
@BeforeClass
public static void startServer() throws Exception {

  if (server == null || !server.isActive()) {

    System.setProperty("ws.maxSessions", Integer.toString(MAX_WS_CONNECTIONS));
    System.setProperty("java.security.egd", "file:/dev/./urandom");

    Properties properties = new Properties();
    properties.put("server.port", getPort());

    SpringApplication application = new SpringApplication(BootTestApplication.class);

    application.setDefaultProperties(properties);

    log.debug("Properties: {}", properties);

    server = application.run();

  }
}