use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project vertx-swagger by bobxwang.
the class SwaggerApp method Run.
public static AnnotationConfigApplicationContext Run(Class<?> clasz) {
final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(clasz);
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(ApplicationContextHolder.class);
applicationContext.registerBeanDefinition("applicationContextHolder", bdb.getBeanDefinition());
// Just For Init
applicationContext.getBean(ApplicationContextHolder.class);
final Environment environment = applicationContext.getBean(Environment.class);
final Vertx vertx = applicationContext.getBean(Vertx.class);
final SpringVerticleFactory verticleFactory = new SpringVerticleFactory();
vertx.registerVerticleFactory(verticleFactory);
try {
applicationContext.getBean(Router.class);
} catch (BeansException be) {
if (be instanceof NoSuchBeanDefinitionException) {
Router rr = new RouterImpl(vertx);
applicationContext.getBeanFactory().registerSingleton("router", rr);
}
}
final Router router = applicationContext.getBean(Router.class);
initSwagger(environment);
configRouter(vertx, router, environment);
Map<String, Verticle> maps = applicationContext.getBeansOfType(Verticle.class);
DeploymentOptions options = new DeploymentOptions().setInstances(1).setWorker(true);
for (Map.Entry<String, Verticle> temp : maps.entrySet()) {
Verticle verticle = temp.getValue();
String name = verticle.getClass().getSimpleName().substring(0, 1).toLowerCase() + verticle.getClass().getSimpleName().substring(1);
vertx.deployVerticle(verticleFactory.prefix() + ":" + name, options);
for (Method method : verticle.getClass().getDeclaredMethods()) {
if (method.isAnnotationPresent(Override.class)) {
continue;
}
if (method.getName().contains("lambda")) {
continue;
}
if (io.swagger.util.ReflectionUtils.isOverriddenMethod(method, verticle.getClass())) {
continue;
}
if (method.isAnnotationPresent(BBRouter.class)) {
BBRouter bbRouter = io.swagger.util.ReflectionUtils.getAnnotation(method, BBRouter.class);
Route route = router.route(bbRouter.httpMethod(), bbRouter.path());
route.handler(ctx -> {
ReflectionUtils.makeAccessible(method);
ReflectionUtils.invokeMethod(method, verticle, ctx);
});
}
}
}
HttpServer httpServer = vertx.createHttpServer(new HttpServerOptions().setSsl(false).setKeyStoreOptions(new JksOptions().setPath("server-keystore.jks").setPassword("secret")));
httpServer.requestHandler(router::accept);
int port;
try {
port = Integer.valueOf(environment.getProperty("server.port", "8080"));
} catch (Exception e) {
throw new RuntimeException("请配置有效端口号");
}
httpServer.listen(port, ar -> {
if (ar.succeeded()) {
logger.info("Server started on port " + ar.result().actualPort());
} else {
logger.error("Cannot start the server: " + ar.cause());
}
});
return applicationContext;
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project dubbo by alibaba.
the class DubboConfigBindingRegistrar method registerDubboConfigBean.
private void registerDubboConfigBean(String beanName, Class<? extends AbstractConfig> configClass, BeanDefinitionRegistry registry) {
BeanDefinitionBuilder builder = rootBeanDefinition(configClass);
AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
registry.registerBeanDefinition(beanName, beanDefinition);
if (log.isInfoEnabled()) {
log.info("The dubbo config bean definition [name : " + beanName + ", class : " + configClass.getName() + "] has been registered.");
}
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project rocketmq-externals by apache.
the class RocketMQAutoConfigurationTests method listenerContainer.
@Test
public void listenerContainer() {
load(false, "spring.rocketmq.nameServer=127.0.0.1:9876");
BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(MyListener.class);
this.context.registerBeanDefinition("myListener", beanBuilder.getBeanDefinition());
this.context.refresh();
assertThat(this.context.getBeansOfType(DefaultRocketMQListenerContainer.class)).isNotEmpty();
assertThat(this.context.containsBean(DefaultRocketMQListenerContainer.class.getName() + "_1")).isTrue();
DefaultRocketMQListenerContainer listenerContainer = this.context.getBean(DefaultRocketMQListenerContainer.class.getName() + "_1", DefaultRocketMQListenerContainer.class);
ObjectMapper objectMapper = this.context.getBean("rocketMQMessageObjectMapper", ObjectMapper.class);
assertThat(listenerContainer.getObjectMapper()).isEqualTo(objectMapper);
assertThat(listenerContainer.getConsumeMode()).isEqualTo(ConsumeMode.CONCURRENTLY);
assertThat(listenerContainer.getSelectorType()).isEqualTo(SelectorType.TAG);
assertThat(listenerContainer.getSelectorExpress()).isEqualTo("*");
assertThat(listenerContainer.getConsumerGroup()).isEqualTo(TEST_CONSUMER_GROUP);
assertThat(listenerContainer.getTopic()).isEqualTo(TEST_TOPIC);
assertThat(listenerContainer.getNameServer()).isEqualTo("127.0.0.1:9876");
assertThat(listenerContainer.getMessageModel()).isEqualTo(MessageModel.CLUSTERING);
assertThat(listenerContainer.getConsumeThreadMax()).isEqualTo(1);
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project pentaho-platform by pentaho.
the class BeanListParser method parseInternal.
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BeanListBuilder.class.getName());
builder.addPropertyValue("type", element.getAttribute("class"));
Map<String, String> propMap = new HashMap<String, String>();
Element objectproperties = DomUtils.getChildElementByTagName(element, Const.ATTRIBUTES);
if (objectproperties != null) {
List props = DomUtils.getChildElementsByTagName(objectproperties, Const.ATTR);
if (props != null) {
for (Object o : props) {
Element prop = (Element) o;
String key = prop.getAttribute(Const.KEY);
String value = prop.getAttribute(Const.VALUE);
propMap.put(key, value);
}
}
}
builder.addPropertyValue(Const.ATTRIBUTES, propMap);
AbstractBeanDefinition definition = builder.getRawBeanDefinition();
definition.setSource(parserContext.extractSource(element));
return definition;
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-security-oauth by spring-projects.
the class ConfigUtils method createSecurityMetadataSource.
public static BeanDefinition createSecurityMetadataSource(Element element, ParserContext pc) {
List<Element> filterPatterns = DomUtils.getChildElementsByTagName(element, "url");
if (filterPatterns.isEmpty()) {
return null;
}
String patternType = element.getAttribute("path-type");
if (!StringUtils.hasText(patternType)) {
patternType = "ant";
}
MatcherType matcherType = MatcherType.valueOf(patternType);
ManagedMap<BeanDefinition, BeanDefinition> invocationDefinitionMap = new ManagedMap<BeanDefinition, BeanDefinition>();
for (Element filterPattern : filterPatterns) {
String path = filterPattern.getAttribute("pattern");
if (!StringUtils.hasText(path)) {
pc.getReaderContext().error("pattern attribute cannot be empty or null", filterPattern);
}
String method = filterPattern.getAttribute("httpMethod");
if (!StringUtils.hasText(method)) {
method = null;
}
String access = filterPattern.getAttribute("resources");
if (StringUtils.hasText(access)) {
BeanDefinition matcher;
if (createMatcherMethod4x != null) {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod4x, matcherType, pc, path, method);
} else {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod3x, matcherType, path, method);
}
if (access.equals("none")) {
invocationDefinitionMap.put(matcher, BeanDefinitionBuilder.rootBeanDefinition(Collections.class).setFactoryMethod("emptyList").getBeanDefinition());
} else {
BeanDefinitionBuilder attributeBuilder = BeanDefinitionBuilder.rootBeanDefinition(SecurityConfig.class);
attributeBuilder.addConstructorArgValue(access);
attributeBuilder.setFactoryMethod("createListFromCommaDelimitedString");
if (invocationDefinitionMap.containsKey(matcher)) {
pc.getReaderContext().warning("Duplicate URL defined: " + path + ". The original attribute values will be overwritten", pc.extractSource(filterPattern));
}
invocationDefinitionMap.put(matcher, attributeBuilder.getBeanDefinition());
}
}
}
BeanDefinitionBuilder fidsBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultFilterInvocationSecurityMetadataSource.class);
fidsBuilder.addConstructorArgValue(invocationDefinitionMap);
fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(element));
return fidsBuilder.getBeanDefinition();
}
Aggregations