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

fix 由于加载延迟在Coniguration中使用mapper报错问题 #5

Merged
merged 1 commit into from
Jan 7, 2018

Conversation

fengcbo
Copy link

@fengcbo fengcbo commented Jan 4, 2018

No description provided.

@abel533
Copy link
Owner

abel533 commented Jan 6, 2018

发现两处问题,第一个是自动配置中没有注入 mapper 配置。

第二个问题就是,RelaxedPropertyResolver 在 spring boot 2.x 中会移除,所以代码中不能直接使用这个类来获取配置。

似乎没有很好的方式可以将 MapperProperties 注入进去。

你有没有更好的建议?

@abel533
Copy link
Owner

abel533 commented Jan 6, 2018

扫描器内做了如下修改:

    public void setMapperProperties(Environment environment) {
        if(environment != null){
            Properties properties = new Properties();
            MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources();
            Iterator<PropertySource<?>> iterator = propertySources.iterator();
            while(iterator.hasNext()){
                PropertySource<?> propertySource = iterator.next();
                if(propertySource instanceof EnumerablePropertySource){
                    EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource)propertySource;
                    String[] propertyNames = enumerablePropertySource.getPropertyNames();
                    for (String propertyName : propertyNames) {
                        if (propertyName.startsWith("mapper.")) {
                            properties.put(propertyName, environment.getProperty(propertyName));
                        }
                    }
                }
            }
            mapperHelper.setProperties(properties);
        }
    }

还没测试。
需要对properties和yml两种进行测试,mappers只能写成xx,xxx不能按数组或者list方式配置。

@abel533
Copy link
Owner

abel533 commented Jan 6, 2018

已经完全解决,等mapper3.5.0版本发布时,这个发布1.2.0版本。

@fengcbo
Copy link
Author

fengcbo commented Jan 6, 2018

期待新版本,顺便问一下,有时间点吗

@abel533
Copy link
Owner

abel533 commented Jan 6, 2018

有,下周一。

@abel533 abel533 merged commit 9f46ab4 into abel533:master Jan 7, 2018
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.

2 participants