Skip to content

Allow usage of @Lazy on injection points [SPR-10353] #14896

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-10353 and commented

To express the lazy referral to a Spring bean, clients can currently use @Inject Provider<T> interface as follows:

class Client {

  @Autowired
  Provider<Server> lazyReferral;

}

To eventually access the bean, the client has to call get() on it. This could be even streamlined by allowing the usage of @Lazy as follows:

class Client {

  @Lazy @Autowired
  Server lazyReferral;

}

During the autowiring this could - in case a unique injection candidate is found - automatically create a ProxyFactoryBean using a LazyInitTargetSource to point to the selected injection target and expose the type of the injection point through the proxy.

The entire scenario of defining the laziness of the access from the client side is really useful in case aspects might need to reach out to user implemented types but want to do this as lazy as possible to prevent initialization cycles (see SEC-2136, DATACMNS-292 for examples).


Issue Links:

  • SEC-2136 Injecting Bean in a class used in custom PermissionEvaluator leads to NoSuchBeanDefinitionException
  • DATACMNS-292 Spring Data Repositories Cannot be used inside Advice w/ an AbstractAdvisorAutoProxyCreator

Referenced from: commits 4447248

1 votes, 2 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions