问题
I'm having a problem using multiple path in component scan. I tried the solution from here How to scan multiple paths using the @ComponentScan annotation? but it gives me error:
@ComponentScan({"com.tx.loader", "com.tx.common"})
@SpringBootApplication
It says
Unexpected tokens (Use ';' to separate expressions on the same line)
I'm using Kotlin and Intellij IDE.
回答1:
Hey in Kotlin I found @ComponentScan
to be a bit tricky.
Here is how I used it, hopefully it matches your case:
@ComponentScan(
// To specify the base package classes
basePackageClasses = [com.tx.loader.Example1::class, com.tx.common.Example2::class]
// Or use this one to specify the package names
basePackages = ["com.tx.loader", "com.tx.common"]
)
Or you could use it in test with the Filter for services or components to autowire only what you need:
import org.springframework.context.annotation.ComponentScan
import org.springframework.stereotype.Component
import org.springframework.stereotype.Service
@ComponentScan(
includeFilters = [ComponentScan.Filter(Service::class), ComponentScan.Filter(Component::class)],
)
来源:https://stackoverflow.com/questions/58811468/using-multiple-path-in-componentscan-is-not-working