我正在处理两个不同的流程。
我在 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方法应该基于传导来调用?
谢谢
拉玛
最佳答案
Spring 有配置文件。根据一组条件,您可以使用精确的配置文件启动应用程序。 Bean beanCreatingBasedOnProfile
将仅在 dev
配置文件中创建。
@Bean
@Profile("dev")
public YourClass beanCreatingBasedOnProfile() {
return new YourClass();
}
Spring 还有 Conditional Beans 。 您可以根据属性值或其他任何内容构建 bean。例如:
@ConditionalOnProperty(prefix = "spring.prop", name = "dynamic", matchIfMissing = true)
public YourClass condBean() {
return new YourClass();
}
关于java - 根据条件调用Spring init方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44289939/