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

Feature: more detailed Datasouce routing support #697

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

yuhuangbin
Copy link

What kind of change does this PR introduce? (check at least one)

Fixed: #695

The description of the PR:
More detailed datasouce routing support and support dynamic configuration refresh.
eg:

spring:
  datasource:
    dynamic:
      enabled: true
      primary: ds1
      aop:
         scan-package-patterns:
          - com.baomidou.simple.service.impl*
         ds-routes:
          '[com.baomidou.simple.service.impl.UserServiceImpl.selectById]': ds2
          '[com.baomidou.simple.service.impl.ds2*]': ds2
      datasource:
        ds1:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://${ip}:${port}/${database}?useUnicode=true&characterEncoding=UTF-8
          username: xxx
          password: xxx
        ds2:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://${ip}:${port}/${database}?useUnicode=true&characterEncoding=UTF-8
          username: xxx
          password: xxx
package com.baomidou.simple.service.impl;

@DS("ds1")
@Service
public class UserServiceImpl implements UserService {
       @Autowired
       private UserMapper userMapper;
       
       public User selectById(Long id) {
           return userMapper.selectById(id);
       }

       public User selectByName(String name) {
           return userMapper.selectByName(name);
       }
}

the UserServiceImpl #selectById() will use ds2, and the UserServiceImpl #selectByName() still using ds1.

Other information:

@yuhuangbin yuhuangbin changed the title More detailed Datasouce routing support Feature: more detailed Datasouce routing support Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More detailed Datasouce routing support
1 participant