2
以下のようなスプリングレストコントローラのカスタムオブジェクトのリストを読み取ることができません。しかし、restowollerのJava BeanにBeanをautowiringしてデータを読み込み/取得することができます。 annonation @valueを使って、残りのコントローラからのデータのリストを読んで助けてもらえますか?プレースホルダを解決できませんでした。文字列値のカスタムオブジェクトのリスト
文字列値 "$ {royalty.testRates}"のプレースホルダのカスタムオブジェクト(royalty.testRates)のリストを解決できませんでした。 YAMLファイルの
コードスニペット: Java Beanが:
@EnableAsync
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(ignoreInvalidFields = false, prefix = "royalty")
@Component
public class RoyaltyMigration {
private List<TestRate> testRates = new ArrayList<TestRate>();
public static class TestRate {
private String channelType;
private String value;
public List<TestRate> getTestRates() {
return testRates;
}
public void setTestRates(List<TestRate> testRates) {
this.testRates = testRates;
}
public String getChannelType() {
return channelType;
}
public void setChannelType(String channelType) {
this.channelType = channelType;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
春休憩コントローラー:javaファイル用
testRates:
- channelType: "WEB"
value: "0.03"
- channelType: "ANDROID_TAB"
value: "0.04"
- channelType: "ANDROID_PHONE"
value: "0.04"
コードスニペット
//@Autowired//Commented
//RoyaltyMigration royaltyMigration; //Commented
@Value("${royalty.testRates}")
private List<RoyaltyMigration.TestRate> testRates;//= new ArrayList<RoyaltyMigration.TestRate>();;
public void setTestRates(List<RoyaltyMigration.TestRate> testRates) {
this.testRates = testRates;
}
@RequestMapping(value = "/testrates", method = {RequestMethod.GET, RequestMethod.POST},
produces = "application/json")
public ResponseEntity<RoyaltyMigration> testRates() {
final RoyaltyMigration royaltyMigration = new RoyaltyMigration();
royaltyMigration.setTestRates(this.testRates);
return new ResponseEntity<>(royaltyMigration, HttpStatus.OK);
}
ここからログイントレース -
を2017-04-02 21:38:46,366 [main] org.springframework.boot.SpringApplication ERROR Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'royaltyMigrationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List com.royalty.controller.RoyaltyMigrationController.testRates; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'royalty.testRates' in string value "${royalty.testRates}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:760)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)
at com.expedia.www.host.loyalty.Starter.main(Starter.java:23)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List com.royalty.controller.LoyaltyMigrationController.testRates; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'loyalty.testRates' in string value "${royalty.testRates}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 17 more
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'royalty.testRates' in string value "${royalty.testRates}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:808)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1027)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 19 more