mercredi 6 juillet 2016

What is the difference between the use of @Import and @ImportResource annotations in Spring framework?

I am studying for the Spring Core certification and I have a doubt related to the @import and the @importresource annotations use.

So for example I have a configuration class named RootConfig.java, this one:

@Configuration
@Import({AppConfig.class,DbConfig.class})
@ImportResource("classpath:/config/security-config.xml")
@EnableTransactionManagement
public class RootConfig {

}

So I know that in this example the:

@Import({AppConfig.class,DbConfig.class})

are importing 2 others configuration classes (something like including these configurations into the main configuration represented by my RootConfig.java configuration class.

Ant I understand that the:

@ImportResource("classpath:/config/security-config.xml")

are importing an XML file.

So my doubt is: why exist 2 differents annotations that do a very similar task? Why don't use a single annotation to import both configurations classes and resources (such as xml files or property files?)

This is only a semantic differentiation or there are something else?

Aucun commentaire:

Enregistrer un commentaire