Skip to content

when use @RefreshScope on @Mapper #476

Closed
@polarloves

Description

@polarloves

I'm trying to get a dynamic datasource on mybatis.
while i use @RefreshScope on dao interface,an exception will occur.
the code is :
ClassPathMapperScanner ,line:196
beacuse it war RootBeanDefinition,not GenericBeanDefinition .
i can only fix it by change the source code on MapperScannerConfigurer :

  ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry) {
            @Override
            public Set<BeanDefinitionHolder> doScan(String... basePackages) {
                Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
                if (!beanDefinitions.isEmpty()) {
                    for (BeanDefinitionHolder beanDefinitionHolder : beanDefinitions) {
                        // set scope
                        beanDefinitionHolder.getBeanDefinition().setScope("refresh");
                    }
                }
                return beanDefinitions;
            }
        };

Metadata

Metadata

Assignees

Labels

enhancementImprove a feature or add a new feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions