如何在 Spring Boot 中从一个目录访问控制器或组件到另一个目录?
How to access a controller or a component from one directory to another in Spring Boot?
试图从父目录访问控制器。我已经使用此方法从子目录调用它。
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample-core</artifactId>
</dependency
上面的用法报错了
[ERROR] /D:/Projects/sample/src/main/java/com/sample/controllers/abcController.java
package com.sample.controller does not exist
如果能帮助我从父目录或其他目录获得访问权限,我们将不胜感激。
您需要向 spring 展示包含其他 类 以扫描超出您当前项目的内容
我认为您正在寻找 @ComponentScan(basePackages={"com.sample"})
告诉 spring 查看您的第三方包
@SpringBootApplication
@EntityScan(basePackages = {"br.com.scan-others-entities-in-other-projects"})
@ComponentScan(basePackages = {"br.com.my-curent-project", "br.com.scan-other-configs-and-controllers"})
@EnableJpaRepositories(basePackages = {"br.com.com-other-repositories"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
试图从父目录访问控制器。我已经使用此方法从子目录调用它。
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample-core</artifactId>
</dependency
上面的用法报错了
[ERROR] /D:/Projects/sample/src/main/java/com/sample/controllers/abcController.java
package com.sample.controller does not exist
如果能帮助我从父目录或其他目录获得访问权限,我们将不胜感激。
您需要向 spring 展示包含其他 类 以扫描超出您当前项目的内容
我认为您正在寻找 @ComponentScan(basePackages={"com.sample"})
告诉 spring 查看您的第三方包
@SpringBootApplication
@EntityScan(basePackages = {"br.com.scan-others-entities-in-other-projects"})
@ComponentScan(basePackages = {"br.com.my-curent-project", "br.com.scan-other-configs-and-controllers"})
@EnableJpaRepositories(basePackages = {"br.com.com-other-repositories"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}