Spring @EnableSpringConfigured not working

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

+4
source share
2 answers

Spring can only configure objects if load time markup is enabled. You must mark your configuration with an @EnableLoadTimeWeavingannotation.

, ,
+1

Entity spring, EntityBuilder create() Entity, , Entity, spring. , spring Engine Entity. , if (engine != null) . spring, spring , , . , .

+1

Source: https://habr.com/ru/post/1687193/


All Articles