本文整理了Java中org.springframework.context.ApplicationContext.getBeansOfType()
方法的一些代码示例,展示了ApplicationContext.getBeansOfType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.getBeansOfType()
方法的具体详情如下:
包路径:org.springframework.context.ApplicationContext
类名称:ApplicationContext
方法名:getBeansOfType
暂无
代码示例来源:origin: spring-projects/spring-framework
private void detectResourceHandlers(ApplicationContext context) {
Map<String, SimpleUrlHandlerMapping> beans = context.getBeansOfType(SimpleUrlHandlerMapping.class);
List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(mappings);
mappings.forEach(mapping ->
mapping.getHandlerMap().forEach((pattern, handler) -> {
if (handler instanceof ResourceWebHandler) {
ResourceWebHandler resourceHandler = (ResourceWebHandler) handler;
this.handlerMap.put(pattern, resourceHandler);
}
}));
if (this.handlerMap.isEmpty()) {
logger.trace("No resource handling mappings found");
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Picks up the instance of the given type from the spring context.
* If there are multiple beans of the same type or if there are none,
* this method treats that as an {@link IllegalArgumentException}.
*
* This method is intended to be used to pick up a Acegi object from
* spring once the bean definition file is parsed.
*/
public static <T> T findBean(Class<T> type, ApplicationContext context) {
Map m = context.getBeansOfType(type);
switch(m.size()) {
case 0:
throw new IllegalArgumentException("No beans of "+type+" are defined");
case 1:
return type.cast(m.values().iterator().next());
default:
throw new IllegalArgumentException("Multiple beans of "+type+" are defined: "+m);
}
}
代码示例来源:origin: spring-projects/spring-framework
protected void detectResourceHandlers(ApplicationContext appContext) {
Map<String, SimpleUrlHandlerMapping> beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(mappings);
for (SimpleUrlHandlerMapping mapping : mappings) {
for (String pattern : mapping.getHandlerMap().keySet()) {
Object handler = mapping.getHandlerMap().get(pattern);
if (handler instanceof ResourceHttpRequestHandler) {
ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler;
this.handlerMap.put(pattern, resourceHandler);
}
}
}
if (this.handlerMap.isEmpty()) {
logger.trace("No resource handling mappings found");
}
}
代码示例来源:origin: AxonFramework/AxonFramework
@Override
public void start() {
if (queryBus == null && !applicationContext.getBeansOfType(QueryBus.class).isEmpty()) {
queryBus = applicationContext.getBean(QueryBus.class);
}
if (queryHandlers == null) {
queryHandlers = applicationContext.getBeansOfType(QueryHandlerAdapter.class).values();
}
queryHandlers.forEach(queryHandler -> queryHandler.subscribe(queryBus));
this.started = true;
}
代码示例来源:origin: codingapi/tx-lcn
@Override
public void destroy() throws Exception {
Map<String, TxLcnInitializer> runnerMap = applicationContext.getBeansOfType(TxLcnInitializer.class);
for (TxLcnInitializer txLcnInitializer : runnerMap.values()) {
txLcnInitializer.destroy();
}
}
}
代码示例来源:origin: codingapi/tx-lcn
@Override
public void run(ApplicationArguments args) throws Exception {
// 取消缓存Runner对象 使用时获取即可
Map<String, TxLcnInitializer> runnerMap = applicationContext.getBeansOfType(TxLcnInitializer.class);
for (TxLcnInitializer txLcnInitializer : runnerMap.values()) {
txLcnInitializer.init();
}
}
代码示例来源:origin: AxonFramework/AxonFramework
@Override
public void afterPropertiesSet() {
factories.addAll(applicationContext.getBeansOfType(ParameterResolverFactory.class).values());
parameterResolverFactory = MultiParameterResolverFactory.ordered(factories);
}
}
代码示例来源:origin: org.springframework.boot/spring-boot
private PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer() {
// Take care not to cause early instantiation of all FactoryBeans
Map<String, PropertySourcesPlaceholderConfigurer> beans = this.applicationContext
.getBeansOfType(PropertySourcesPlaceholderConfigurer.class, false, false);
if (beans.size() == 1) {
return beans.values().iterator().next();
}
if (beans.size() > 1 && logger.isWarnEnabled()) {
logger.warn(
"Multiple PropertySourcesPlaceholderConfigurer " + "beans registered "
+ beans.keySet() + ", falling back to Environment");
}
return null;
}
代码示例来源:origin: Activiti/Activiti
public static ProcessEngine buildProcessEngine(URL resource) {
log.debug("==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE =========================================");
ApplicationContext applicationContext = new GenericXmlApplicationContext(new UrlResource(resource));
Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class);
if ((beansOfType == null) || (beansOfType.isEmpty())) {
throw new ActivitiException("no " + ProcessEngine.class.getName() + " defined in the application context " + resource.toString());
}
ProcessEngine processEngine = beansOfType.values().iterator().next();
log.debug("==== SPRING PROCESS ENGINE CREATED ==================================================================");
return processEngine;
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setup() {
this.context = new ClassPathXmlApplicationContext(
"scheduledTasksContext.xml", ScheduledTasksBeanDefinitionParserTests.class);
this.registrar = this.context.getBeansOfType(
ScheduledTaskRegistrar.class).values().iterator().next();
this.testBean = this.context.getBean("testBean");
}
代码示例来源:origin: AxonFramework/AxonFramework
@Override
@SuppressWarnings("unchecked")
public void start() {
if (commandBus == null && !applicationContext.getBeansOfType(CommandBus.class).isEmpty()) {
commandBus = applicationContext.getBean(CommandBus.class);
}
if (commandHandlers == null) {
commandHandlers = applicationContext.getBeansOfType(MessageHandler.class).values();
}
commandHandlers.stream().filter(commandHandler -> commandHandler instanceof CommandMessageHandler)
.forEach(commandHandler -> {
for (String commandName : ((CommandMessageHandler) commandHandler).supportedCommandNames()) {
commandBus.subscribe(commandName, commandHandler);
}
});
this.started = true;
}
代码示例来源:origin: shuzheng/zheng
for(Object service : baseServices.values()) {
LOGGER.debug(">>>>> {}.initMapper()", service.getClass().getName());
try {
Map<String, BaseInterface> baseInterfaceBeans = contextRefreshedEvent.getApplicationContext().getBeansOfType(BaseInterface.class);
for(Object service : baseInterfaceBeans.values()) {
LOGGER.debug(">>>>> {}.init()", service.getClass().getName());
try {
代码示例来源:origin: AxonFramework/AxonFramework
private void initialize() {
enhancers.addAll(ClasspathHandlerEnhancerDefinition.forClassLoader(classLoader).getDelegates());
Map<String, HandlerEnhancerDefinition> enhancersFound = applicationContext.getBeansOfType(
HandlerEnhancerDefinition.class);
enhancers.addAll(enhancersFound.values());
}
}
代码示例来源:origin: AxonFramework/AxonFramework
private void initialize() {
definitions.addAll(ClasspathHandlerDefinition.forClassLoader(classLoader).getDelegates());
Map<String, HandlerDefinition> definitionsFound = applicationContext.getBeansOfType(HandlerDefinition.class);
definitions.addAll(definitionsFound.values());
}
}
代码示例来源:origin: org.springframework.boot/spring-boot
private void callRunners(ApplicationContext context, ApplicationArguments args) {
List<Object> runners = new ArrayList<>();
runners.addAll(context.getBeansOfType(ApplicationRunner.class).values());
runners.addAll(context.getBeansOfType(CommandLineRunner.class).values());
AnnotationAwareOrderComparator.sort(runners);
for (Object runner : new LinkedHashSet<>(runners)) {
if (runner instanceof ApplicationRunner) {
callRunner((ApplicationRunner) runner, args);
}
if (runner instanceof CommandLineRunner) {
callRunner((CommandLineRunner) runner, args);
}
}
}
代码示例来源:origin: geoserver/geoserver
public Object create(Class clazz) {
if (applicationContext != null) {
Collection extensions =
applicationContext.getBeansOfType(GeoServerFactory.Extension.class).values();
for (Iterator e = extensions.iterator(); e.hasNext(); ) {
Extension extension = (Extension) e.next();
if (extension.canCreate(clazz)) {
return extension.create(clazz);
}
}
}
return null;
}
}
代码示例来源:origin: aol/micro-server
private void addAutoDiscoveredServlets(ServletContext webappContext) {
serverData
.getRootContext()
.getBeansOfType(ServletConfiguration.class)
.values()
.forEach(servlet -> handleServlet(servlet,webappContext));
}
代码示例来源:origin: org.springframework/spring-webmvc
protected void detectResourceHandlers(ApplicationContext appContext) {
Map<String, SimpleUrlHandlerMapping> beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(mappings);
for (SimpleUrlHandlerMapping mapping : mappings) {
for (String pattern : mapping.getHandlerMap().keySet()) {
Object handler = mapping.getHandlerMap().get(pattern);
if (handler instanceof ResourceHttpRequestHandler) {
ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler;
this.handlerMap.put(pattern, resourceHandler);
}
}
}
if (this.handlerMap.isEmpty()) {
logger.trace("No resource handling mappings found");
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Actually register the endpoints. Called by {@link #afterSingletonsInstantiated()}.
*/
protected void registerEndpoints() {
Set<Class<?>> endpointClasses = new LinkedHashSet<>();
if (this.annotatedEndpointClasses != null) {
endpointClasses.addAll(this.annotatedEndpointClasses);
}
ApplicationContext context = getApplicationContext();
if (context != null) {
String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class);
for (String beanName : endpointBeanNames) {
endpointClasses.add(context.getType(beanName));
}
}
for (Class<?> endpointClass : endpointClasses) {
registerEndpoint(endpointClass);
}
if (context != null) {
Map<String, ServerEndpointConfig> endpointConfigMap = context.getBeansOfType(ServerEndpointConfig.class);
for (ServerEndpointConfig endpointConfig : endpointConfigMap.values()) {
registerEndpoint(endpointConfig);
}
}
}
代码示例来源:origin: aol/micro-server
public LinkedListX getRestResources(ApplicationContext rootContext){
List resources = new ArrayList<>();
module.getRestResourceClasses().forEach(it -> resources.addAll(rootContext.getBeansOfType(it).values()));
module.getRestAnnotationClasses().forEach(it -> resources.addAll(rootContext.getBeansWithAnnotation(it).values()));
rootContext.getBeansWithAnnotation(JaxRsResource.class).forEach((n,it)->resources.add(it));
rootContext.getBeansOfType(JaxRsResourceWrapper.class).forEach((n,it)->resources.add(it.getResource()));
resources.addAll(module.getJaxRsResourceObjects());
return LinkedListX.fromIterable(resources);
}
内容来源于网络,如有侵权,请联系作者删除!