Java 多模块组件扫描在spring boot中不工作

Java 多模块组件扫描在spring boot中不工作,java,spring,spring-boot,Java,Spring,Spring Boot,我有两个模块:网络和商务。我已经把商业纳入了网络。但当我尝试使用@autowired将业务服务接口包含到web中时,它给出了org.springframework.beans.factory.NoSuchBeanDefinitionException 因此,基本上,@SpringBootApplication无法从业务模块扫描@服务 是不是很简单,我错过了什么 如果我在@SpringBootApplication类中为该服务添加@Bean,它工作正常 代码: 来自模块1的类,从中调用来自模块2的

我有两个模块:网络和商务。我已经把商业纳入了网络。但当我尝试使用
@autowired
将业务服务接口包含到web中时,它给出了
org.springframework.beans.factory.NoSuchBeanDefinitionException

因此,基本上,
@SpringBootApplication
无法从业务模块扫描
@服务

是不是很简单,我错过了什么

如果我在
@SpringBootApplication
类中为该服务添加
@Bean
,它工作正常

代码:

来自模块1的类,从中调用来自模块2的类:

package com.manish.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.co.smithnews.pmp.service.contract.UserRegistrationService;

@RestController
@RequestMapping("/testManish")
public class SampleController {

    @Autowired
    private SampleService sampleService;
....
}
单元2:

package com.manish.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SampleServiceImpl implements SampleService {
}

谢谢,

@SpringBootApplication
只扫描带有注释本身的类的包以及下面的所有包

示例:如果带有SpringBootApplication注释的类位于包
com.project.web
中,则扫描此包和下面的所有包

但是,如果您的服务在包
com.project.business
中,则不会扫描bean


在这种情况下,您必须将注释
@ComponentScan()
添加到您的应用程序类中,并在该注释中添加所有要扫描为值的包,例如
@ComponentScan({“com.project.web”,“com.project.business”})

我的多个模块具有相同的基本包,我将配置保留在基本备份的根目录下。所以,这不应该是一个问题。那么,你必须提供更多关于你的项目结构等的信息。组件扫描不关心,如果你的类存储在不同的JAR中,只要它们在类路径上。我已经添加了我的代码,但一切看起来都很简单。感谢您还可以@ComponentScan(basePackages={“com.project”})这将扫描所有com.project包。*您如何构建和运行应用程序?你能发布你的构建配置吗?谢谢dunni,我的代码中有一个类型导致了这个问题。当我试图为你粘贴代码时,我发现了。
package com.manish.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SampleServiceImpl implements SampleService {
}