Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

Speed up YAML file processing in Spring boot

I'm trying to read YAML properties file using the @PropertySource annotation in Spring Boot.
configuration.yaml file has about 7.5K lines of data in the below format:

# Configuration for privilege management
---
role-configuration:
  roles:
    - name: Agent
      groups:
        -name: privilege-group
group-configuration:
  groups:
    - name: privilege-group
privilege-configuration:
  privileges:
    - name: admin-dashboard-view
      description: View Admin dashboard
      groups:
        - name: privilege-group
    - name: admin-dashboard-edit
      description: Edit Admin dashboard
      groups:
        - name: privilege-group
     ....
     ...
     ..

Configuration bean and YAML specific PropertySourceFactory has been implemented by following this link

PrivilegeProvider.java

@Configuration
@ConfigurationProperties(prefix = "privilege-configuration")
@PropertySource(value = "classpath:security/configuration.yaml", factory = YamlPropertySourceFactory.class)
@Data # lombok annotation for generating getter/setter and other helper functions
public class PrivilegeProvider {
    private List<Privilege> privileges;
}

YamlPropertySourceFactory.java

public class YamlPropertySourceFactory implements PropertySourceFactory {
    @Override
    public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) throws IOException {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(encodedResource.getResource());

        Properties properties = factory.getObject();

        return new PropertiesPropertySource(encodedResource.getResource().getFilename(), properties);
    }
}

All the data is successfully loaded from YAML file but it is taking ~5-7 minutes to load, which is quite a lot of time given the file size.

Can this be optimized? or is there any other way in which I can implement the same?

question from:https://stackoverflow.com/questions/65835520/speed-up-yaml-file-processing-in-spring-boot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...