我有这样一个物化实体类春@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/>
。请提供一个使用主观声明而不是自动装配的解决方案。