Search code examples
javaspringspring-bootspring-boot-test

I can't manage to do a ComponentScan from a test packages to main packages


is there anyone who would know the way how to use a @ComponentScan(basePackages = {}) from class inside "test" directory to point on a packages in "main" directory.

For instance:

@Configuration
@ComponentScan(basePackages = {com.package.inside.main.directory.package1,
      com.package.inside.main.directory.package2 })
public class TestConfiguration{}

I tried this way but when i type the package name it doesn't recognize the ones outside the test directory


Solution

  • What do you mean? The value of "basePackages" should be a string array. So you can input any string there. Like:

    @ComponentScan(basePackages = {"com.package.inside.main.directory.package1",
    "com.package.inside.main.directory.package2","any package is ok" })