Using multiple path in @ComponentScan is not working

眉间皱痕 提交于 2020-08-09 12:31:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!