I am trying to use @EnableSpringConfigured, but this does not work.
Engine.java
@Component
public class Engine {
public void run() {
System.out.println("Engine run");
}
}
Entity.java
@Component
@Configurable(autowire = Autowire.BY_TYPE)
public class Entity {
@Autowired
private Engine engine;
public void exec() {
if (engine != null)
engine.run();
else
System.out.println("exec failure");
}
}
EntityBuilder.java
@Component
public class EntityBuilder {
public Entity create() {
return new Entity();
}
}
EntityApplication.java
@Configuration
@ComponentScan
@EnableSpringConfigured
public class EntityApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(EntityApplication.class);
EntityBuilder builder = context.getBean(EntityBuilder.class);
builder.create().exec();
}
}
The above four java in one package, I will try to run EntityApplication.java and expect to see "Run Engine", but the actual result is always "exec crash".
help! the code is at https://github.com/lemonguge/spring/tree/master/spring-core/spring-aspect/src/main/java/cn/homjie/spring/aspect/newx
source
share