public ResourceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); Resource resource = ae.getAnnotation(Resource.class); String resourceName = resource.name(); Class<?> resourceType = resource.type(); this.isDefaultName = !StringUtils.hasLength(resourceName); if (this.isDefaultName) { resourceName = this.member.getName(); if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) { resourceName = Introspector.decapitalize(resourceName.substring(3)); } } else if (embeddedValueResolver != null) { resourceName = embeddedValueResolver.resolveStringValue(resourceName); } if (Object.class != resourceType) { checkResourceType(resourceType); } else { // No resource type specified... check field/method. resourceType = getResourceType(); } this.name = (resourceName != null ? resourceName : ""); this.lookupType = resourceType; String lookupValue = resource.lookup(); this.mappedName = (StringUtils.hasLength(lookupValue) ? lookupValue : resource.mappedName()); Lazy lazy = ae.getAnnotation(Lazy.class); this.lazyLookup = (lazy != null && lazy.value()); }
@Lazy @Bean(name = "dataformat-component") @ConditionalOnMissingBean(DataFormatComponent.class) public DataFormatComponent configureDataFormatComponent() throws Exception { DataFormatComponent component = new DataFormatComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); for (Map.Entry<String, Object> entry : parameters.entrySet()) { CamelPropertiesHelper.setCamelProperties(camelContext, component, parameters, false); if (ObjectHelper.isNotEmpty(customizers)) { for (ComponentCustomizer<DataFormatComponent> customizer : customizers) { boolean useCustomizer = (customizer instanceof HasId) "camel.component.customizer", "camel.component.dataformat.customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate( applicationContext.getEnvironment(),
/** * Provide a lazy {@link JobExecutionStateMachine} bean if one hasn't already been defined. * * @param stateMachine The state machine to use for job execution * @return A {@link JobExecutionStateMachineImpl} instance */ @Bean @Lazy @ConditionalOnMissingBean(JobExecutionStateMachine.class) public JobExecutionStateMachine jobExecutionStateMachine(final StateMachine<States, Events> stateMachine) { return new JobExecutionStateMachineImpl(stateMachine); }
@Lazy @Bean @ConditionalOnMissingBean @ConditionalOnClass(CamelContext.class) public CamelReactiveStreamsService camelReactiveStreamsService() throws Exception { ReactiveStreamsEngineConfiguration engineConfiguration = new ReactiveStreamsEngineConfiguration(); if (configuration.getInternalEngineConfiguration() != null) { Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration.getInternalEngineConfiguration(), parameters, null, false); IntrospectionSupport.setProperties(context, context.getTypeConverter(), engineConfiguration, parameters); } return ReactiveStreamsHelper.resolveReactiveStreamsService(context, configuration.getServiceType(), engineConfiguration); }
@Lazy @Bean(name = "ribbon-load-balancer") @ConditionalOnClass(CamelContext.class) public ServiceLoadBalancer configureLoadBalancerFactory() throws Exception { RibbonServiceLoadBalancerFactory factory = new RibbonServiceLoadBalancerFactory(); IntrospectionSupport.setProperties( camelContext, camelContext.getTypeConverter(), factory, IntrospectionSupport.getNonNullProperties(configuration)); return factory.newInstance(camelContext); }
@Resource @Lazy public void setTestBean(TestBean testBean) { this.testBean = testBean; } }
@Lazy @Bean(name = "stub-component") @ConditionalOnMissingBean(StubComponent.class) public StubComponent configureStubComponent() throws Exception { StubComponent component = new StubComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); for (Map.Entry<String, Object> entry : parameters.entrySet()) { CamelPropertiesHelper.setCamelProperties(camelContext, component, parameters, false); if (ObjectHelper.isNotEmpty(customizers)) { for (ComponentCustomizer<StubComponent> customizer : customizers) { boolean useCustomizer = (customizer instanceof HasId) "camel.component.customizer", "camel.component.stub.customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate( applicationContext.getEnvironment(),
/** * Provide a lazy {@link LaunchJobService} bean if one hasn't already been defined. * * @return A {@link LaunchJobServiceImpl} instance */ @Bean @Lazy @ConditionalOnMissingBean(LaunchJobService.class) public LaunchJobService launchJobService() { return new LaunchJobServiceImpl(); } }
@Lazy @Bean(name = "dns-service-discovery") @ConditionalOnClass(CamelContext.class) public ServiceDiscovery configureServiceDiscoveryFactory() throws Exception { DnsServiceDiscoveryFactory factory = new DnsServiceDiscoveryFactory(); IntrospectionSupport.setProperties( camelContext, camelContext.getTypeConverter(), factory, IntrospectionSupport.getNonNullProperties(configuration)); return factory.newInstance(camelContext); }
@Component @Lazy static class LazyBean { @JmsListener(destination = "myQueue") public void handle(String msg) { } }
@Lazy @Bean(name = "class-component") @ConditionalOnMissingBean(ClassComponent.class) public ClassComponent configureClassComponent() throws Exception { ClassComponent component = new ClassComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); for (Map.Entry<String, Object> entry : parameters.entrySet()) { CamelPropertiesHelper.setCamelProperties(camelContext, component, parameters, false); if (ObjectHelper.isNotEmpty(customizers)) { for (ComponentCustomizer<ClassComponent> customizer : customizers) { boolean useCustomizer = (customizer instanceof HasId) "camel.component.customizer", "camel.component.class.customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate( applicationContext.getEnvironment(),
/** * Provide a lazy execution context bean if one hasn't already been defined. * * @return An {@link ExecutionContextImpl} instance */ @Bean @Lazy @ConditionalOnMissingBean(ExecutionContext.class) public ExecutionContext executionContext() { return new ExecutionContextImpl(); } }
/** * @author Mark Fisher */ @Component("myNamedComponent") @Lazy public class NamedComponent { }
protected boolean isLazy(DependencyDescriptor descriptor) { for (Annotation ann : descriptor.getAnnotations()) { Lazy lazy = AnnotationUtils.getAnnotation(ann, Lazy.class); if (lazy != null && lazy.value()) { return true; } } MethodParameter methodParam = descriptor.getMethodParameter(); if (methodParam != null) { Method method = methodParam.getMethod(); if (method == null || void.class == method.getReturnType()) { Lazy lazy = AnnotationUtils.getAnnotation(methodParam.getAnnotatedElement(), Lazy.class); if (lazy != null && lazy.value()) { return true; } } } return false; }
@Lazy @Bean(name = "rest-component") @ConditionalOnMissingBean(RestComponent.class) public RestComponent configureRestComponent() throws Exception { RestComponent component = new RestComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); for (Map.Entry<String, Object> entry : parameters.entrySet()) { CamelPropertiesHelper.setCamelProperties(camelContext, component, parameters, false); if (ObjectHelper.isNotEmpty(customizers)) { for (ComponentCustomizer<RestComponent> customizer : customizers) { boolean useCustomizer = (customizer instanceof HasId) "camel.component.customizer", "camel.component.rest.customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate( applicationContext.getEnvironment(),
/** * Provide a lazy {@link DownloadService} bean if one hasn't already been defined. * * @param fetchingCacheService The cache service to use * @return A {@link DownloadServiceImpl} instance */ @Bean @Lazy @ConditionalOnMissingBean(DownloadService.class) public DownloadService downloadService(final FetchingCacheService fetchingCacheService) { return new DownloadServiceImpl(fetchingCacheService); }
public static class OptionalFieldResourceInjectionBean implements TestBeanHolder { @Autowired(required = false) @Lazy private TestBean testBean; @Autowired(required = false) @Lazy private List<TestBean> testBeans; public TestBean getTestBean() { return this.testBean; } public List<TestBean> getTestBeans() { return this.testBeans; } }