Java Code Examples for org.springframework.context.annotation.AnnotationConfigApplicationContext#getBeanProvider()
The following examples show how to use
org.springframework.context.annotation.AnnotationConfigApplicationContext#getBeanProvider() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectProviderDemo.java From geekbang-lessons with Apache License 2.0 | 5 votes |
private static void lookupByStreamOps(AnnotationConfigApplicationContext applicationContext) { ObjectProvider<String> objectProvider = applicationContext.getBeanProvider(String.class); // Iterable<String> stringIterable = objectProvider; // for (String string : stringIterable) { // System.out.println(string); // } // Stream -> Method reference objectProvider.stream().forEach(System.out::println); }
Example 2
Source File: ObjectProviderDemo.java From geekbang-lessons with Apache License 2.0 | 4 votes |
private static void lookupIfAvailable(AnnotationConfigApplicationContext applicationContext) { ObjectProvider<User> userObjectProvider = applicationContext.getBeanProvider(User.class); User user = userObjectProvider.getIfAvailable(User::createUser); System.out.println("当前 User 对象:" + user); }
Example 3
Source File: ObjectProviderDemo.java From geekbang-lessons with Apache License 2.0 | 4 votes |
private static void lookupByObjectProvider(AnnotationConfigApplicationContext applicationContext) { ObjectProvider<String> objectProvider = applicationContext.getBeanProvider(String.class); System.out.println(objectProvider.getObject()); }
Example 4
Source File: TypeSafetyDependencyLookupDemo.java From geekbang-lessons with Apache License 2.0 | 4 votes |
private static void displayObjectProviderStreamOps(AnnotationConfigApplicationContext applicationContext) { ObjectProvider<User> userObjectProvider = applicationContext.getBeanProvider(User.class); printBeansException("displayObjectProviderStreamOps", () -> userObjectProvider.forEach(System.out::println)); }
Example 5
Source File: TypeSafetyDependencyLookupDemo.java From geekbang-lessons with Apache License 2.0 | 4 votes |
private static void displayObjectProviderIfAvailable(AnnotationConfigApplicationContext applicationContext) { ObjectProvider<User> userObjectProvider = applicationContext.getBeanProvider(User.class); printBeansException("displayObjectProviderIfAvailable", () -> userObjectProvider.getIfAvailable()); }
Example 6
Source File: TypeSafetyDependencyLookupDemo.java From geekbang-lessons with Apache License 2.0 | 4 votes |
private static void displayObjectFactoryGetObject(AnnotationConfigApplicationContext applicationContext) { // ObjectProvider is ObjectFactory ObjectFactory<User> userObjectFactory = applicationContext.getBeanProvider(User.class); printBeansException("displayObjectFactoryGetObject", () -> userObjectFactory.getObject()); }
Example 7
Source File: NamedContextFactory.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
public <T> ObjectProvider<T> getProvider(String name, Class<T> type) { AnnotationConfigApplicationContext context = getContext(name); return context.getBeanProvider(type); }