Replies: 1 comment 3 replies
-
아래와 같이 enum type을 반환하는 메서드를 추가한 뒤 @Component
public class Bean1 implements EnumMappedBean {
@Override
public SomeEnum getSomeEnum() {
return SomeEnum.ENUM1;
}
} Config 클래스에 enum과 bean을 맵핑한 빈을 등록하면 @Configuration
public class AppConfig {
@Bean
public Map<SomeEnum, EnumMappedBean> getBeansMappedByEnum(@NonNull Collection<EnumMappedBean> enumBeans) {
return enumBeans.stream()
.collect(toMap(EnumMappedBean::getSomeEnum, Function.identity()));
}
} 서비스에서 enum type을 키로 사용하는 맵을 주입받을 수 있는 것 같습니다. @Service
public class SomeOtherBean {
private Map<SomeEnum, EnumMappedBean> beansMappedByEnum;
@Autowired
public SomeOtherBean(@NonNull Map<SomeEnum, EnumMappedBean> beansMappedByEnum) {
this.beansMappedByEnum = beansMappedByEnum;
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
#84 (comment)
Beta Was this translation helpful? Give feedback.
All reactions