Search results
Inject a java.util.Map from a YAML file in Spring Boot applications
- Map<String, String>
application.yml
:
asimiotech:
layouts:
default: layouts/default/main
acme: layouts/acme/main
Spring Boot Configuration Class
:
@Configuration
@EnableConfigurationProperties
public class AppConfig {
@Bean
@ConfigurationProperties("asimiotech.layouts")
public Map<String, String> layouts() {
return new HashMap<>();
}
// ...
}
Spring Bean Java Class
:
@RequiredArgsConstructor
public class SpringBean {
private final Map<String, String> layouts;
// ...
}
or
public class SpringBean {
@Autowired
private Map<String, String> layouts;
// ...
}
Also related to this page:
Recipe to Inject a java.util.Map from a Properties file in Spring applications
Recipe to Inject a java.util.Map from a Properties file in Spring applications