Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scoped proxy on mapper scan feature #484

Merged
merged 1 commit into from
Jun 21, 2020

Conversation

kazuki43zoo
Copy link
Member

@kazuki43zoo kazuki43zoo commented Jun 21, 2020

Fixes gh-476

By this change, the develop become can specified scope of mapper using mapper scan feature option and scope annotation(@Scope, @RefreshScope, etc ...).
The defaultScope apply to the mapper bean(MapperFactoryBean) when scope of scanned bean definition is singleton (default scope) and create a scoped proxy bean for scanned mapper when final scope is not singleton.

Usage option on mapper scan feature

The developer can specify the scope of mapper bean that not specified scope annotation using option of mapper scan feature.

Using @MapperScan

@Cpnfiguration
@MapperScan(defaultScope = "refresh")
class MyBatisConfig {
  // ...
}

Using MapperScannerConfigurer

@Bean
MapperScannerConfigurer mapperScannerConfigurer() {
  MapperScannerConfigurer configurer = new MapperScannerConfigurer();
  configurer.setDefaultScope("refresh");
  // ...
  return  configurer;
}

Using XML Namespace(<mybatis:scan/>)

<mybatis:scan base-package="org.mybatis.spring.mapper" default-scope="refresh" />

Using scope annotation

The developer can specify the scope per mapper using scope annotation.

// equiv to @Scope(scopeName = "refresh", proxyMode = ScopedProxyMode.TARGET_CLASS)
@RefreshScope
@Mapper 
public interface MyMapper {
  // ...
}

@kazuki43zoo kazuki43zoo added the enhancement Improve a feature or add a new feature label Jun 21, 2020
@kazuki43zoo kazuki43zoo added this to the 2.0.6 milestone Jun 21, 2020
@kazuki43zoo kazuki43zoo self-assigned this Jun 21, 2020
@kazuki43zoo kazuki43zoo merged commit 6b4c5e8 into mybatis:master Jun 21, 2020
kazuki43zoo added a commit that referenced this pull request Jun 21, 2020
@kazuki43zoo kazuki43zoo deleted the gh-476_support-scoped-proxy branch June 21, 2020 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve a feature or add a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when use @RefreshScope on @Mapper
1 participant