GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — @Mapper(componentModel = "spring") doesn't support custom name for Spring Service Annotation · Issue #1427 · mapstruct/mapstruct

@Mapper(componentModel = "spring") doesn't support custom name for Spring Service Annotation #1427

New issue
Copy link
New issue
Copy link
Closed
#3019
Closed
@Mapper(componentModel = "spring") doesn't support custom name for Spring Service Annotation#1427
#3019
Copy link
Labels
enhancementgood first issue
Milestone
1.6.0.Beta1

Description

@zurbergram
zurbergram
opened on Apr 13, 2018
Issue body actions

Can't specify a name for the Spring Service annotation
If the interface definition something like

@Mapper(componentModel = "spring", componentModelName = "cakeMapperV2")
 public interface CakeMapper{
     Cake map(Cupcake cupcake);
 }

 @Service("cakeMapperV2")
 public class CakeMapperImpl {
 }
Reacted by Matteo, Simon Tenbeitel, Stephen Fox, Semyon Levin, Jim and Nikhil Nagrale
Reacted by Dmitriy Belyaev

Activity

Next
  1. filiphr
    added
    enhancement
    on Apr 14, 2018
  2. filiphr
    added this to the Future planning milestone on Apr 14, 2018
  3. filiphr
    added
    good first issue
    on Apr 14, 2018
  4. filiphr commented on Apr 14, 2018

    @filiphr
    filiphr
    on Apr 14, 2018
    Member
    More actions

    @zurbergram yes this is not possible in the moment out of the box.

    However, there is a way for you to achieve what you are looking for with some internal customizations. We have an internal SPI ModelElementProcessor that adds the spring @Component annotation. The one for Spring is the SpringComponentProcessor.

    What you can do is to define your own ModelElementProcessor that would be of a custom component model, provide your own marker annotation for the name of the component and you would be able to do what you are looking for.

    Just keep in mind that this is an internal SPI, which means that we cannot guarantee backwards compatibility between versions. However, it is rarely changed.

  5. chris922
    added 6 commits that reference this issue on Apr 18, 2018

    mapstruct#1427 Add additional configuration for Jsr330 and Spring co…

    9616e0a

    mapstruct#1427 Add additional configuration for Jsr330 and Spring co…

    2b442bd

    mapstruct#1427 Add additional configuration for Jsr330 and Spring co…

    1821871

    mapstruct#1427 Add additional configuration for Jsr330 and Spring co…

    065d3b9

    mapstruct#1427 Add additional configuration for Jsr330 and Spring co…

    d1d9a8f

    mapstruct#1427 Add additional configuration for Jsr330 and Spring co…

    283c3a7
  6. chris922 commented on Apr 18, 2018

    @chris922
    chris922
    on Apr 18, 2018
    Member
    More actions

    Oups, sorry! I wasn't aware about the fact that changes in my forked mapstruct repo will directly be linked to this issue. Hopefully I haven't spammed you with too much notification mails.

    @filiphr as my changes are now linked here maybe you could already take a look or should I create a PR? (this is my more or less first 'real' OS contribution; right now I am waiting that the built finishs locally including all tests)

    I tried to add the possibility to have an extra annotation (@MapperSpringConfig / @MapperJsr330Config) to be able to have more component model specific configurations, e. g. if @Service or @Component should be used and - as requested in this ticket - to define an own bean name.

    Maybe its better to extend the @Mapper configuration with a new property like componentName, but my idea was that there are maybe also other configuration things that only belongs to a special componentModel and having a special annotation for this could be helpful for those usecases.

  7. filiphr
    modified the milestones: Future planning, This milestone has been deleted on Apr 21, 2018
  8. chris922
    added a commit that references this issue on Apr 24, 2018

    mapstruct#1427 Add additional configuration for Jsr330 and Spring co…

    962d4ec
  9. filiphr
    removed this from the 1.3.0.Beta2 milestone on Oct 11, 2018
  10. 12 remaining items

  11. Zegveld
    added 2 commits that reference this issue on Jun 5, 2022

    mapstruct#1427: AnnotateWith now also usable for Spring "Component" a…

    a1fcfd2

    Revert "mapstruct#1427: AnnotateWith now also usable for Spring "Comp…

    241eceb
  12. jccampanero commented on Sep 4, 2022

    @jccampanero
    jccampanero
    on Sep 4, 2022
    Contributor
    More actions

    Adding this to 1.6 in order to be able to think of a solution that would work correctly with #1574

    @filiphr Please, could you elaborate the idea?

  13. filiphr commented on Sep 5, 2022

    @filiphr
    filiphr
    on Sep 5, 2022
    Member
    More actions

    With #1574 one can now write a mapper that looks like:

    @Mapper(componentModel = "spring")
    @AnnotateWith(value = Component.class, elements = @Element(strings = "myCustomMapperName"))
    public interface MyCustomMapper {
    
    }

    This will now generate

    @Component("myCustomMapperName")
    @Component
    public interface MyCustomMapper {
    
    }

    This is of course invalid.

    What we need to do is to make sure that we are properly handling this, i.e. not adding the @Component in AnnotationBasedComponentModelProcessor.

    We'll need to make sure that the following things work:

    • Works properly with delegator
    • Works properly when a different specialization of @Component is used. e.g. if @Service is used with @AnnotateWith
    Reacted by Dmitriy Belyaev
  14. jccampanero commented on Sep 5, 2022

    @jccampanero
    jccampanero
    on Sep 5, 2022
    Contributor
    More actions

    Thank you very much for your explanation @filiphr.

    So, basically, it is necessary to finish the work already started on this commit, making sure it works properly with delegator and with other Spring related annotations, is that correct?

    I will be glad to work in the issue if you wish.

  15. jccampanero
    added a commit that references this issue on Sep 10, 2022

    mapstruct#1427 Prevent the inclusion of @component if Mapper is alrea…

    fd7edb7
  16. jccampanero commented on Sep 11, 2022

    @jccampanero
    jccampanero
    on Sep 11, 2022
    Contributor
    More actions

    Hi @filiphr.

    It's nice talking to you again.

    I have been working on the issue, I have provided a possible implementation mainly based on the code that you and @Zegveld developed.

    I tried performing some initial testing of the decorator related stuff and it seems to work properly.

    One question came to mind though: when using a decorator, if we have a component where we have a custom name, shouldn't be that name the one used in the generated @Qualifier annotation instead of the default delegate? In the present code, it works properly because of the precedence of the @Qualifier annotation but it is a common practice in Spring to qualify by the custom name provided when annotating the component or service.

    I created a PR with the changes performed: please, feel free to ask me to change anything you think is appropriate.

    Thank you very much.

  17. jccampanero
    added 4 commits that reference this issue on Sep 26, 2022

    mapstruct#1427 Improve @component annotation processing.

    0994e91

    mapstruct#1427 Test only the generated source code, without Spring co…

    db24200

    mapstruct#1427 Test related Mappers code simplification.

    658aa6d

    mapstruct#1427 Remove Decorator test related stuff. Restore original …

    cd2923d
  18. filiphr
    closed this as completedin #3019on Oct 1, 2022
  19. filiphr
    added a commit that references this issue on Oct 1, 2022

    #1427 Add support for custom name in Spring stereotype annotations

    90a487a
  20. filiphr commented on Oct 1, 2022

    @filiphr
    filiphr
    on Oct 1, 2022
    Member
    More actions

    This was implemented using the new @AnnotateWith.

    This means that the one can do:

    @AnnotateWith(value = Service.class, elements = @Element(strings = "cakeMapperV2"))
    @Mapper(componentModel = "spring")
    public interface CakeMapper{
         Cake map(Cupcake cupcake);
     }

    And that will generate:

     @Service("cakeMapperV2")
     public class CakeMapperImpl {
     }
    Reacted by salpreh, AlexElin, James Wang and Giulio Longfils
    Reacted by Carlos Freund and Zsolt Katona
  21. chenzijia12300
    added a commit that references this issue on Oct 2, 2022

    mapstruct#1427 Add support for custom name in Spring stereotype annot…

    7a1d877
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      • 1.6.0.Beta1

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.