@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { environment = applicationContext.getEnvironment(); PropertySourcesPlaceholderConfigurer cfg = applicationContext.getBean( "org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0", PropertySourcesPlaceholderConfigurer.class); localPropertySource = cfg.getAppliedPropertySources() .get(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME); }
/** * Returns a property value from the application context. * * @param name Property name. * @return Property value, or null if not found. */ public static String getProperty(String name) { ApplicationContext appContext = getRootAppContext(); if (appContext == null) { return null; } String value = appContext.getEnvironment().getProperty(name); if (value == null) { PropertySourcesPlaceholderConfigurer cfg = appContext.getBean(PropertySourcesPlaceholderConfigurer.class); PropertySource<?> ps = cfg.getAppliedPropertySources().get( PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME); value = ps == null ? null : (String) ps.getProperty(name); } return value; }
private static void startServer() { Object port = ctx.getBean(PropertySourcesPlaceholderConfigurer.class).getAppliedPropertySources().get("localProperties").getProperty("server.port"); ctx.getBean(NettyServer.class).start(Integer.parseInt(port.toString())); }