/*
* Copyright 2017 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.cnten.vertx;
import io.vertx.core.Verticle;
import io.vertx.core.spi.VerticleFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* A {@link VerticleFactory} backed by Spring's {@link ApplicationContext}. It allows to implement verticles as Spring
* beans and thus benefit from dependency injection, ...etc.
*
* @author Thomas Segismont
*/
@Component
public class SpringVerticleFactory implements VerticleFactory, ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public boolean blockingCreate() {
// Usually verticle instantiation is fast but since our verticles are Spring Beans,
// they might depend on other beans/resources which are slow to build/lookup.
return true;
}
@Override
public String prefix() {
// Just an arbitrary string which must uniquely identify the verticle factory
return "myapp";
}
@Override
public Verticle createVerticle(String verticleName, ClassLoader classLoader) throws Exception {
// Our convention in this example is to give the class name as verticle name
String clazz = VerticleFactory.removePrefix(verticleName);
return (Verticle) applicationContext.getBean(Class.forName(clazz));
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
vertx for springboot.zip (27个子文件)
device-gather
pom.xml 7KB
.springBeans 476B
target
test-classes
com
cnten
TcpClientTest.class 1KB
DeviceGatherApplicationTests.class 632B
classes
META-INF
maven
com.cnten
device-gather
pom.xml 7KB
pom.properties 240B
vertx-springboot-demo
pom.xml 7KB
pom.properties 248B
MANIFEST.MF 353B
application.yml 274B
com
cnten
handler
CntenAsyncHandler.class 1KB
DeviceGatherApplication.class 2KB
vertx
SpringVerticleFactory.class 2KB
SpringVerticleManager.class 3KB
.vertx
file-cache-4700830f-a421-4085-8354-329b23101276
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.core.resources.prefs 155B
org.eclipse.jdt.core.prefs 243B
src
test
java
com
cnten
DeviceGatherApplicationTests.java 348B
TcpClientTest.java 968B
main
asciidoc
dataobjects.adoc 505B
resources
application.yml 274B
java
com
cnten
handler
CntenAsyncHandler.java 515B
DeviceGatherApplication.java 2KB
vertx
SpringVerticleManager.java 2KB
SpringVerticleFactory.java 2KB
.project 773B
.classpath 1KB
共 27 条
- 1
资源评论
- twssy2020-03-30没有价值的资源
陕西赢益园林科技有限公司
- 粉丝: 12
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功