[英]Call Spring init method based on condiction
我正在2个不同的过程。
我在JVM参数中传递了进程名称。 使用该参数,任何一个进程都应调用。
我的应用上下文XML。
<bean id="propertyPlaceHolderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:properties/${processJVMArg}.properties</value>
</list>
</property>
</bean>
<bean id="splitService" class="com.split.service.SplitService" init-method="process1"><!-- "based on processJVMArg JVM argument should call process1 or process2. " -->
有没有一种方法可以配置多个init方法,init方法应该基于传导调用?
谢谢,
拉玛
春天有档案。 根据条件设置,您可以使用准确的配置文件启动应用程序。 Bean beanCreatingBasedOnProfile
仅在dev
配置文件中创建。
@Bean
@Profile("dev")
public YourClass beanCreatingBasedOnProfile() {
return new YourClass();
}
春天也有条件豆 。 您可以根据属性值或其他任何值构造bean。 例如:
@ConditionalOnProperty(prefix = "spring.prop", name = "dynamic", matchIfMissing = true)
public YourClass condBean() {
return new YourClass();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.