feat: 修改GlobalConfig的生成方法,由于目前无法在代码层面修改已加载后的GlobalConfig,所以做出这个修改 #6693
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这样就可以在ConfigurationCustomizer上去修改GlobalConfig,同时不会影响已加载的配置。

比如用到了mysql和oracle两种数据库,但是根据当前是有的数据库使用不同的字段包装符合,有一个 columnForamt的配置可以做到,但是由于这个配置在
global-config
中的db-config
配置中,所以无法在代码中动态的根据当前的数据源进行修改。目前只能通过重新实例化 SqlSessionFacotry 的办法解决,但这样一来就会导致配置文件中的默认配置全部失效。而
SqlSessionFactoryBeanCustomizer
虽然可以在原来已加载配置的基础上修改配置,但是由于设置globalConfig
的方法在调用这个方法的后面,所以无法生效通过修改GlobalConfigUtils中的defaults方法可以让
global-config
对象全局唯一,这样在SqlSessionFactoryBeanCustomizer
的修改的配置不会被后面的代码覆盖