Java Code Examples for org.springframework.core.ResolvableType#forMethodReturnType()
The following examples show how to use
org.springframework.core.ResolvableType#forMethodReturnType() .
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: GenericTypeAwareAutowireCandidateResolver.java From java-technology-stack with MIT License | 6 votes |
@Nullable protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) { // Should typically be set for any kind of factory method, since the BeanFactory // pre-resolves them before reaching out to the AutowireCandidateResolver... ResolvableType returnType = rbd.factoryMethodReturnType; if (returnType == null) { Method factoryMethod = rbd.getResolvedFactoryMethod(); if (factoryMethod != null) { returnType = ResolvableType.forMethodReturnType(factoryMethod); } } if (returnType != null) { Class<?> resolvedClass = returnType.resolve(); if (resolvedClass != null && descriptor.getDependencyType().isAssignableFrom(resolvedClass)) { // Only use factory method metadata if the return type is actually expressive enough // for our dependency. Otherwise, the returned instance type may have matched instead // in case of a singleton instance having been registered with the container already. return returnType; } } return null; }
Example 2
Source File: GenericTypeAwareAutowireCandidateResolver.java From lams with GNU General Public License v2.0 | 6 votes |
protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) { // Should typically be set for any kind of factory method, since the BeanFactory // pre-resolves them before reaching out to the AutowireCandidateResolver... ResolvableType returnType = rbd.factoryMethodReturnType; if (returnType == null) { Method factoryMethod = rbd.getResolvedFactoryMethod(); if (factoryMethod != null) { returnType = ResolvableType.forMethodReturnType(factoryMethod); } } if (returnType != null) { Class<?> resolvedClass = returnType.resolve(); if (resolvedClass != null && descriptor.getDependencyType().isAssignableFrom(resolvedClass)) { // Only use factory method metadata if the return type is actually expressive enough // for our dependency. Otherwise, the returned instance type may have matched instead // in case of a singleton instance having been registered with the container already. return returnType; } } return null; }
Example 3
Source File: GenericTypeAwareAutowireCandidateResolver.java From spring-analysis-note with MIT License | 6 votes |
@Nullable protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) { // Should typically be set for any kind of factory method, since the BeanFactory // pre-resolves them before reaching out to the AutowireCandidateResolver... ResolvableType returnType = rbd.factoryMethodReturnType; if (returnType == null) { Method factoryMethod = rbd.getResolvedFactoryMethod(); if (factoryMethod != null) { returnType = ResolvableType.forMethodReturnType(factoryMethod); } } if (returnType != null) { Class<?> resolvedClass = returnType.resolve(); if (resolvedClass != null && descriptor.getDependencyType().isAssignableFrom(resolvedClass)) { // Only use factory method metadata if the return type is actually expressive enough // for our dependency. Otherwise, the returned instance type may have matched instead // in case of a singleton instance having been registered with the container already. return returnType; } } return null; }
Example 4
Source File: GenericTypeAwareAutowireCandidateResolver.java From blog_demos with Apache License 2.0 | 6 votes |
protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) { // Should typically be set for any kind of factory method, since the BeanFactory // pre-resolves them before reaching out to the AutowireCandidateResolver... Class<?> preResolved = rbd.resolvedFactoryMethodReturnType; if (preResolved != null) { return ResolvableType.forClass(preResolved); } else { Method resolvedFactoryMethod = rbd.getResolvedFactoryMethod(); if (resolvedFactoryMethod != null) { if (descriptor.getDependencyType().isAssignableFrom(resolvedFactoryMethod.getReturnType())) { // Only use factory method metadata if the return type is actually expressive enough // for our dependency. Otherwise, the returned instance type may have matched instead // in case of a singleton instance having been registered with the container already. return ResolvableType.forMethodReturnType(resolvedFactoryMethod); } } return null; } }
Example 5
Source File: GenericTypeAwareAutowireCandidateResolver.java From spring4-understanding with Apache License 2.0 | 6 votes |
protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) { // Should typically be set for any kind of factory method, since the BeanFactory // pre-resolves them before reaching out to the AutowireCandidateResolver... Class<?> preResolved = rbd.resolvedFactoryMethodReturnType; if (preResolved != null) { return ResolvableType.forClass(preResolved); } else { Method resolvedFactoryMethod = rbd.getResolvedFactoryMethod(); if (resolvedFactoryMethod != null) { if (descriptor.getDependencyType().isAssignableFrom(resolvedFactoryMethod.getReturnType())) { // Only use factory method metadata if the return type is actually expressive enough // for our dependency. Otherwise, the returned instance type may have matched instead // in case of a singleton instance having been registered with the container already. return ResolvableType.forMethodReturnType(resolvedFactoryMethod); } } return null; } }
Example 6
Source File: VaadinControlInitializer.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void initialize(Object control, String property, InitializationConfig config) { if (this.dao == null) { log.warn("Nothing to do without persistent service"); return; } Class<?> clazz = config.getType(); PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(clazz, property); if (pd == null) { log.error("Not found property descriptor for property [" + property + "]") ; return; } ResolvableType propertyType = ResolvableType.forMethodReturnType(pd.getReadMethod()); Annotation[] annotations = getAnnotations(property, clazz); for (Annotation a : annotations) { List<Object> items = null; if (ManyToOne.class.equals(a.annotationType()) || ManyToMany.class.equals(a.annotationType()) ) { items = getEntityList(propertyType, config.getSortPropertyName()); } else if (Reference.class.equals(a.annotationType())) { Reference r = (Reference) a; Class<?> type = void.class.equals(r.target()) ? propertyType.resolve() : r.target(); List<Object> entities = getEntityList(type, config.getSortPropertyName()); items = StringUtils.isEmpty(r.property()) ? entities : getValueList(entities, r.property()); } if (items != null) { if (control instanceof AbstractSelect) { for (Object item : items) ((AbstractSelect) control).addItem(item); } break; } } }
Example 7
Source File: ConfigurationPropertiesBindingPostProcessor.java From spring-cloud-gray with Apache License 2.0 | 5 votes |
private ResolvableType getBeanType(Object bean, String beanName) { Method factoryMethod = this.beanFactoryMetadata.findFactoryMethod(beanName); if (factoryMethod != null) { return ResolvableType.forMethodReturnType(factoryMethod); } return ResolvableType.forClass(bean.getClass()); }
Example 8
Source File: NacosBootConfigurationPropertiesBinder.java From nacos-spring-boot-project with Apache License 2.0 | 5 votes |
private ResolvableType getBeanType(Object bean, String beanName) { Method factoryMethod = this.beanFactoryMetadata.findFactoryMethod(beanName); if (factoryMethod != null) { return ResolvableType.forMethodReturnType(factoryMethod); } return ResolvableType.forClass(bean.getClass()); }
Example 9
Source File: ServiceMethodInfo.java From spring-cloud-sockets with Apache License 2.0 | 5 votes |
public ServiceMethodInfo(Method method) { this.method = method; ReactiveSocket annotated = AnnotatedElementUtils.findMergedAnnotation(method, ReactiveSocket.class); if(annotated == null){ throw new IllegalStateException("Service methods must be annotated with a one of {@OneWayMapping, @RequestOneMapping, @RequestManyMapping, @RequestStreamMapping} "); } this.mappingInfo = new ServiceMappingInfo(annotated.value(), annotated.mimeType(), annotated.exchangeMode()); this.returnType = ResolvableType.forMethodReturnType(method); findPayloadParameter(); validate(); }
Example 10
Source File: SpringBootTest.java From FastBootWeixin with Apache License 2.0 | 5 votes |
public static void main1(String[] args) throws NoSuchMethodException { Method method = WxApp.class.getMethod("cardMessage", String.class); ResolvableType resolvableType = ResolvableType.forMethodReturnType(method); ResolvableType arrayType = ResolvableType.forArrayComponent(ResolvableType.forClass(WxMessage.class)); ResolvableType iterableType = ResolvableType.forClassWithGenerics(Iterable.class, WxMessage.class); System.out.println(resolvableType); }
Example 11
Source File: FunctionDetectorCondition.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
private static List<String> pruneFunctionBeansForKafkaStreams(List<String> strings, ConditionContext context) { final List<String> prunedList = new ArrayList<>(); for (String key : strings) { final Class<?> classObj = ClassUtils.resolveClassName(((AnnotatedBeanDefinition) context.getBeanFactory().getBeanDefinition(key)) .getMetadata().getClassName(), ClassUtils.getDefaultClassLoader()); try { Method[] methods = classObj.getMethods(); Optional<Method> kafkaStreamMethod = Arrays.stream(methods).filter(m -> m.getName().equals(key)).findFirst(); if (kafkaStreamMethod.isPresent()) { Method method = kafkaStreamMethod.get(); ResolvableType resolvableType = ResolvableType.forMethodReturnType(method, classObj); final Class<?> rawClass = resolvableType.getGeneric(0).getRawClass(); if (rawClass == KStream.class || rawClass == KTable.class || rawClass == GlobalKTable.class) { prunedList.add(key); } } } catch (Exception e) { LOG.error("Function not found: " + key, e); } } return prunedList; }
Example 12
Source File: KafkaStreamsFunctionBeanPostProcessor.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
private void extractResolvableTypes(String key) { final Class<?> classObj = ClassUtils.resolveClassName(((AnnotatedBeanDefinition) this.beanFactory.getBeanDefinition(key)) .getMetadata().getClassName(), ClassUtils.getDefaultClassLoader()); try { Method[] methods = classObj.getMethods(); Optional<Method> kafkaStreamMethod = Arrays.stream(methods).filter(m -> m.getName().equals(key)).findFirst(); if (kafkaStreamMethod.isPresent()) { Method method = kafkaStreamMethod.get(); ResolvableType resolvableType = ResolvableType.forMethodReturnType(method, classObj); final Class<?> rawClass = resolvableType.getGeneric(0).getRawClass(); if (rawClass == KStream.class || rawClass == KTable.class || rawClass == GlobalKTable.class) { if (onlySingleFunction) { resolvableTypeMap.put(key, resolvableType); } else { final String definition = streamFunctionProperties.getDefinition(); if (definition == null) { throw new IllegalStateException("Multiple functions found, but function definition property is not set."); } else if (definition.contains(key)) { resolvableTypeMap.put(key, resolvableType); } } } } } catch (Exception e) { LOG.error("Function activation issues while mapping the function: " + key, e); } }
Example 13
Source File: BeanWrapperImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public ResolvableType getResolvableType() { return ResolvableType.forMethodReturnType(this.pd.getReadMethod()); }
Example 14
Source File: SerdesProvidedAsBeansTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 4 votes |
@Test public void testKstreamWordCountFunction() throws NoSuchMethodException { SpringApplication app = new SpringApplication(SerdeProvidedAsBeanApp.class); app.setWebApplicationType(WebApplicationType.NONE); try (ConfigurableApplicationContext context = app.run( "--server.port=0", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.process-in-0.destination=purchases", "--spring.cloud.stream.bindings.process-out-0.destination=coffee", "--spring.cloud.stream.kafka.streams.binder.functions.process.applicationId=process-id-0", "--spring.cloud.stream.kafka.streams.binder.configuration.commit.interval.ms=1000", "--spring.cloud.stream.kafka.streams.binder.configuration.default.key.serde" + "=org.apache.kafka.common.serialization.Serdes$StringSerde", "--spring.cloud.stream.kafka.streams.binder.configuration.default.value.serde" + "=org.apache.kafka.common.serialization.Serdes$StringSerde", "--spring.cloud.stream.kafka.streams.binder.brokers=" + embeddedKafka.getBrokersAsString())) { final Method method = SerdeProvidedAsBeanApp.class.getMethod("process"); ResolvableType resolvableType = ResolvableType.forMethodReturnType(method, SerdeProvidedAsBeanApp.class); final KeyValueSerdeResolver keyValueSerdeResolver = context.getBean(KeyValueSerdeResolver.class); final BindingServiceProperties bindingServiceProperties = context.getBean(BindingServiceProperties.class); final KafkaStreamsExtendedBindingProperties kafkaStreamsExtendedBindingProperties = context.getBean(KafkaStreamsExtendedBindingProperties.class); final ConsumerProperties consumerProperties = bindingServiceProperties.getBindingProperties("process-in-0").getConsumer(); final KafkaStreamsConsumerProperties kafkaStreamsConsumerProperties = kafkaStreamsExtendedBindingProperties.getExtendedConsumerProperties("input"); kafkaStreamsExtendedBindingProperties.getExtendedConsumerProperties("input"); final Serde<?> inboundValueSerde = keyValueSerdeResolver.getInboundValueSerde(consumerProperties, kafkaStreamsConsumerProperties, resolvableType.getGeneric(0)); Assert.isTrue(inboundValueSerde instanceof FooSerde, "Inbound Value Serde is not matched"); final ProducerProperties producerProperties = bindingServiceProperties.getBindingProperties("process-out-0").getProducer(); final KafkaStreamsProducerProperties kafkaStreamsProducerProperties = kafkaStreamsExtendedBindingProperties.getExtendedProducerProperties("output"); kafkaStreamsExtendedBindingProperties.getExtendedProducerProperties("output"); final Serde<?> outboundValueSerde = keyValueSerdeResolver.getOutboundValueSerde(producerProperties, kafkaStreamsProducerProperties, resolvableType.getGeneric(1)); Assert.isTrue(outboundValueSerde instanceof FooSerde, "Outbound Value Serde is not matched"); } }
Example 15
Source File: BeanWrapperImpl.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public ResolvableType getResolvableType() { return ResolvableType.forMethodReturnType(this.pd.getReadMethod()); }
Example 16
Source File: BeanWrapperImpl.java From java-technology-stack with MIT License | 4 votes |
@Override public ResolvableType getResolvableType() { return ResolvableType.forMethodReturnType(this.pd.getReadMethod()); }
Example 17
Source File: BeanWrapperImpl.java From spring-analysis-note with MIT License | 4 votes |
@Override public ResolvableType getResolvableType() { return ResolvableType.forMethodReturnType(this.pd.getReadMethod()); }