我正在开发一个版本为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)
但我还是一样 …
我正在学习春天,我只是在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)