我有這樣一個物化實體類春@Configurable與JavaConfig在GAE上,物化班
@Entity
@Cache
@Index
public class DummyEntity {
@Id private Long id;
private ObjectifyStartup objectifyStartup;
private String someData;
//Getters and setters for all
}
這ObjectifyStartup
是Web MVC JavaConfig文件初始化一個bean,我需要注入任何DummyEntity
例如
@EnableWebMvc
@Configuration
public class SpringWebMvcConfig extends WebMvcConfigurerAdapter {
@Bean
public ObjectifyStartup objectifyStartup() { return new ObjectifyStartupImpl(); }
}
我想這樣做某處代碼,基本上在控制器
DummyEntity newDummy = new DummyEntity();
我知道我需要在DummyEntity
上使用@Configurable
註釋來使Spring容器注入依賴關係,但是我必須將此類DI的JavaConfig代碼放入SpringWebMvcConfig
類中才能使用此DI。
由於此處提到的最佳做法Spring GAE Optimization中的自動裝配,我無法使用自動裝配,組件掃描,因爲GAE中的性能受到影響。我遇到的所有解決方案都使用@Autowired
與@ComponentScan
和<context:spring-configured/>
。請提供一個使用主觀聲明而不是自動裝配的解決方案。