Skip to content

Introduce a mechanism for abstract types at component scanning [SPR-11663] #16286

Closed
@spring-projects-issues

Description

@spring-projects-issues

cemo koc opened SPR-11663 and commented

I would like to create some proxy beans based on interfaces. I will provide some basic examples to make clear.

Use case 1: Creating a proxy restful client based on interface

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Restful {
   String value() default "";
}

@Restful 
public interface MyRestClient {

  @Get("/events/{year}/{location}")
  EventList getEventsByYearAndLocation(int year, String location);

 }

Use case 2: Creating a proxy repository instance based on interfaces

@MyRepository // new annotation
public interface PersonRepository {
   List<Person> findByLastnameOrderByFirstnameAsc(String lastname);
  List<Person> findByLastnameOrderByFirstnameDesc(String lastname);
}

In order to provide this functionality I had to dig many codes from Spring Data project and became little frustrated with result. I had to create 6-7 class and most of them are duplicated. As a result of my implementation basically I had to create a custom InstantiationAwareBeanPostProcessorAdapter to create beans with custom logic after registering them.

I would like to see a configuration mechanism for registering beans for abstract types dynamically. I was considering an API for component scanning such as ComponentScanProcessor. Each registered ComponentScanProcessor can decide about candidates.

This will help to reduce a fair amount codes in many projects even Spring Data which is creating repository beans from Interfaces.


Affects: 4.0.3

Issue Links:

3 votes, 6 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions