@EnableAutoConfiguration - excludeName

时间:2017-04-09 23:11:37

标签: tomcat spring-boot

I am working on a Springboot application, where a server startup (Tomcat) initializes bunch of classes. There are some unwanted ones being initialized and I am trying to improve the performance of startup so dont want to iniztialze these classes. I tried using @EnableAutoConfiguration annotation in my SpringBootServletInitializer with excludeName parameter as below :

@EnableAutoConfiguration(excludeName  = "com.foler.subfolder.ExampleClass")

I also tried with another parameter @EnableAutoConfiguration(exclude = ExampelClass.class)

1 个答案:

答案 0 :(得分:1)

There are some unwanted ones being initialized and I am trying to improve the performance of startup so don't want to initialize these classes.

Auto-configuration (using @EnableAutoConfiguration) is always applied after user-defined beans have been registered, look here from the API here on the same point.

So, you should actually use @ComponentScan to filter the classes as part of the scanning so that the container might speed up (as it will not create bean objects from excluded packages/classes during the container startup).

@ComponentScan(basePackages = {"com.foler"}, 
        excludeFilters = @ComponentScan.Filter(
                           type=FilterType.ASSIGNABLE_TYPE,
                           value = ExampelClass.class))

Is there any way I can add two or more classes for value parameter?

values accepts the type Class[] array , so you can set the multiple classses as value = {ExampelClass1.class, ExampelClass2.class}