Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[feature suggestion] Support component injection in abstract base class #2257

@incaseoftrouble

Description

@incaseoftrouble

Another one :-)

Suppose I have a mapper like this:

@Mapper // with proper configuration of componentModel, injectionStrategy = CONSTRUCTOR, etc.
public abstract class Mapper {
  @Autowired
  private SpringComponent component;

  // mapping methods
}

This works, however using the recommended constructor injection

@Mapper // with proper configuration of componentModel etc.
public abstract class Mapper {
  private final SpringComponent component;

  @Autowired
  Mapper(SpringComponent component) {
    this.component = component;
  }

  // mapping methods
}

does not work, since the generated mapper always requires a default constructor to be present. I suggest that if a single @Autowired constructor (or equivalent for other component models) is found, it takes the arguments and adds it to the generated constructor (including @Qualifier annotations etc.)

This is sort of low priority because using field injection on the base mapper still works, but would be nice to have I think.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions