Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于条件调用Spring init方法_Java_Spring_Spring Bean - Fatal编程技术网

Java 基于条件调用Spring init方法

Java 基于条件调用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

我在做两种不同的工作

我正在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. " -->

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框架参考文档-