小编Akk*_*kki的帖子

spring.main.allow-bean-definition-overriding=true 被忽略并抛出 ConflictingBeanException

我正在开发一个版本为2.2.0的 spring-boot 应用程序。

我想覆盖 spring-boot 默认提供的 bean。所以我spring.main.allow-bean-definition-overriding=true在我的workflow.properties文件中尝试过。

两个java文件中的代码是相同的,一个是默认提供的bean,另一个是我创建的。唯一的区别是,我创建的java文件将加载我提供的资源,而不是默认bean(来自spring-boot)加载默认资源。

workflow.properties在我的主应用程序中加载这样的扩展org.springframework.boot.web.servlet.support.SpringBootServletInitializer

@Override
protected SpringApplicationBuilder configure( SpringApplicationBuilder application )
{
    application.application().setDefaultProperties( getProperties() );
    return application.sources( WorkflowServiceApplication.class );
}

public static void main( String[] args )
    {
        // SpringApplication.run( WorkflowServiceApplication.class, args );
        new SpringApplicationBuilder( WorkflowServiceApplication.class ).properties( "spring.config.name:workflow" )
                                                                        .build()
                                                                        .run( args );
    }

static Properties getProperties()
{
    Properties props = new Properties();

    props.put( "spring.config.name", "workflow" );

    props.put( "spring.config.location", "../conf/" );
    return props;
}
Run Code Online (Sandbox Code Playgroud)

但我还是一样 …

java spring-boot

7
推荐指数
1
解决办法
1062
查看次数

在Bean类中使用ApplicationContextAware来初始化原型范围bean成员

我正在学习春天,我只是在ApplicationContextAware和豆荚一起玩.

我将附上代码,然后描述我想要做的事情.

到目前为止,我已经创建了一个

点类:

public class Point {
private int x;
private int y;

public int getX() {
    return x;
}
public void setX(int x) {
    this.x = x;
}
public int getY() {
    return y;
}
public void setY(int y) {
    this.y = y;
}

@Override
public String toString() {
    return "x: "+this.x+",y: "+this.y;
}

}
Run Code Online (Sandbox Code Playgroud)

我创建了一个Triangle类,它有3个Point类的实例:

public class Triangle implements ApplicationContextAware, BeanNameAware{

private Point pointA;
private Point pointB;
private Point pointC;
private …
Run Code Online (Sandbox Code Playgroud)

java spring

5
推荐指数
1
解决办法
74
查看次数

标签 统计

java ×2

spring ×1

spring-boot ×1