Java 基于条件调用Spring init方法
我在做两种不同的工作 我正在JVM参数中传递进程名。使用该参数,两个进程中的任何一个都应该调用 我的应用程序上下文XMLJava 基于条件调用Spring init方法,java,spring,spring-bean,Java,Spring,Spring Bean,我在做两种不同的工作 我正在JVM参数中传递进程名。使用该参数,两个进程中的任何一个都应该调用 我的应用程序上下文XML <bean id="propertyPlaceHolderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list
<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. " -->
classpath*:properties/${processJVMArg}.properties
是否有一种方法可以配置多个init方法,init方法应该基于传导进行调用
谢谢
拉玛春天有轮廓。根据一组条件,您可以使用精确的配置文件启动应用程序。Bean
beanCreatingBasedOnProfile
将仅在dev
profile中创建
@Bean
@Profile("dev")
public YourClass beanCreatingBasedOnProfile() {
return new YourClass();
}
春天也来了。
您可以基于属性值或其他任何内容构造bean。例如:
@ConditionalOnProperty(prefix = "spring.prop", name = "dynamic", matchIfMissing = true)
public YourClass condBean() {
return new YourClass();
}
Spring有一些轮廓。根据一组条件,您可以使用精确的配置文件启动应用程序。Bean
beanCreatingBasedOnProfile
将仅在dev
profile中创建
@Bean
@Profile("dev")
public YourClass beanCreatingBasedOnProfile() {
return new YourClass();
}
春天也来了。
您可以基于属性值或其他任何内容构造bean。例如:
@ConditionalOnProperty(prefix = "spring.prop", name = "dynamic", matchIfMissing = true)
public YourClass condBean() {
return new YourClass();
}
基于传导?这在编程中意味着什么?您应该考虑使用Spring的Profile特性。请参阅Spring框架参考文档-基于传导?这在编程中意味着什么?您应该考虑使用Spring的Profile特性。请参阅Spring框架参考文档-