@Override public void initialize(ConfigurableWebApplicationContext applicationContext) { // test that ApplicationContextInitializers can access ServletContext properties // via the environment (SPR-8991) String value = applicationContext.getEnvironment().getRequiredProperty("someProperty"); assertThat(value, is("someValue")); } }
@Override @SuppressWarnings("unchecked") public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException { T property = delegate.getRequiredProperty(key, targetType); if (property != null && targetType == String.class) { property = (T) maybeDecrypt((String) property); } return property; }
@Override public String getRequiredProperty(String key) throws IllegalStateException { return maybeDecrypt(delegate.getRequiredProperty(key)); }
public static void main(String[] args) { // 创建、扫描并启动注解配置驱动应用上下文 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AnnotationPropertySourceBootstrap.class); ConfigurableEnvironment environment = context.getEnvironment(); // 输出 "user.name" 和 "java.naming.factory.initial" 属性 System.out.println("user.name = " + environment.getRequiredProperty("user.name")); System.out.println("java.naming.factory.initial = " + environment.getRequiredProperty("java.naming.factory.initial")); // 关闭上下文 context.close(); }
@Override @SuppressWarnings("unchecked") public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException { T property = delegate.getRequiredProperty(key, targetType); if (property != null && targetType == String.class) { property = (T) maybeDecrypt((String) property); } return property; }
@Override public String getRequiredProperty(String key) throws IllegalStateException { return maybeDecrypt(delegate.getRequiredProperty(key)); }
public JettyServerContainer startJetty(Map<String, Object> properties) throws Exception { long start = currentTimeMillis(); // also CXF uses JDK logging SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); ConfigurableEnvironment env = new NflowStandardEnvironment(properties); String host = env.getRequiredProperty("host"); int port = env.getRequiredProperty("port", Integer.class); KillProcess.gracefullyTerminateOrKillProcessUsingPort(port, env.getRequiredProperty("terminate.timeout", Integer.class), true); Server server = setupServer(); setupJmx(server, env); setupServerConnector(server, host, port); ServletContextHandler context = setupServletContextHandler(env.getRequiredProperty("extra.resource.directories", String[].class)); setupHandlers(server, context, env); setupSpring(context, env); setupCxf(context); setupMetricsAdminServlet(context); server.start(); long end = currentTimeMillis(); JettyServerContainer startedServer = new JettyServerContainer(server); port = startedServer.getPort(); logger.info("Successfully started Jetty on port {} in {} seconds in environment {}", port, (end - start) / 1000.0, Arrays.toString(env.getActiveProfiles())); logger.info("API available at http://{}:{}/nflow/api/", host, port); logger.info("Swagger available at http://{}:{}/nflow/ui/doc/", host, port); logger.info("Explorer available at http://{}:{}/nflow/ui/explorer/", host, port); logger.info("Metrics and health checks available at http://{}:{}/nflow/metrics/", host, port); return startedServer; }