为了账号安全,请及时绑定邮箱和手机立即绑定

Spring Boot 无法扫描多个模块的注释

Spring Boot 无法扫描多个模块的注释

12345678_0001 2024-01-25 10:31:53
我使用 Spring Boot 并通过多个模块进行设计。下面是我的项目结构:模块商店核心:包名称:com.baotrung.core.business 我设计了一些子包:模型,存储库,服务行长:<modelVersion>4.0.0</modelVersion>    <artifactId>shop-core</artifactId>    <packaging>jar</packaging>    <dependencies>        <!-- shop-core-model !-->        <dependency>            <groupId>com.baotrung</groupId>            <artifactId>shop-core-model</artifactId>            <version>0.0.1-SNAPSHOT</version>        </dependency>        <dependency>            <groupId>org.apache.commons</groupId>            <artifactId>commons-lang3</artifactId>            <version>3.9</version>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-data-jpa</artifactId>        </dependency>    </dependencies>类别服务 public interface CategoryService {    List<Object> countProductsByCategories(MerchantStore store, List<Long> categoryIds);    List<Category> listByStoreAndParent(MerchantStore store, Category category);    PersistableCategory saveCategories(MerchantStore store, PersistableCategory persistableCategory);    Category findById(Long id);    List<ReadableCategory> findCategories(MerchantStore store, int dept, Language language,List<String> filters);}类别 服务实施@Servicepublic class CategoryServiceImpl implements CategoryService {    @Autowired    private CategoriesRepository categoryRepository;    @Autowired    private LanguageRepository languageRepository;    @Autowired    private Mapper<Category,ReadableCategory> categoryReadableCategoryMapper;    //some method@存储库public interface CategoriesRepository extends CrudRepository<Category, Long>, CategoryRepositoryCustom { }public interface CategoryRepositoryCustom {    List<Object> countProductsByCategories(MerchantStore store, List<Long> categoryIds);    List<Category> listByStoreAndParent(MerchantStore store, Category category);    }@Repositorypublic class CategoryRepositoryCustomImpl implements CategoryRepositoryCustom {// some method impl}
查看完整描述

2 回答

?
开满天机

TA贡献1786条经验 获得超12个赞

我使用 Spring Boot 并通过多个模块进行设计。下面是我的项目结构:


模块商店核心:包名称:com.baotrung.core.business 我设计了一些子包:模型,存储库,服务


行长:


<modelVersion>4.0.0</modelVersion>


    <artifactId>shop-core</artifactId>

    <packaging>jar</packaging>


    <dependencies>

        <!-- shop-core-model !-->

        <dependency>

            <groupId>com.baotrung</groupId>

            <artifactId>shop-core-model</artifactId>

            <version>0.0.1-SNAPSHOT</version>

        </dependency>


        <dependency>

            <groupId>org.apache.commons</groupId>

            <artifactId>commons-lang3</artifactId>

            <version>3.9</version>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-data-jpa</artifactId>

        </dependency>



    </dependencies>

类别服务


 public interface CategoryService {


    List<Object> countProductsByCategories(MerchantStore store, List<Long> categoryIds);


    List<Category> listByStoreAndParent(MerchantStore store, Category category);


    PersistableCategory saveCategories(MerchantStore store, PersistableCategory persistableCategory);


    Category findById(Long id);


    List<ReadableCategory> findCategories(MerchantStore store, int dept, Language language,List<String> filters);

}


类别 服务实施


@Service

public class CategoryServiceImpl implements CategoryService {


    @Autowired

    private CategoriesRepository categoryRepository;


    @Autowired

    private LanguageRepository languageRepository;


    @Autowired

    private Mapper<Category,ReadableCategory> categoryReadableCategoryMapper;


    //some method

@存储库


public interface CategoriesRepository extends CrudRepository<Category, Long>, CategoryRepositoryCustom {


 }


public interface CategoryRepositoryCustom {


    List<Object> countProductsByCategories(MerchantStore store, List<Long> categoryIds);


    List<Category> listByStoreAndParent(MerchantStore store, Category category);



    }


@Repository

public class CategoryRepositoryCustomImpl implements CategoryRepositoryCustom {


// some method impl

}

我还创建了模块shopping-app p 并在其中使用了商店代码依赖项。看起来像 :


查看完整回答
反对 回复 2024-01-25
?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

我建议您清理/重组您的包层次结构以使其正常工作。

如果您将Application 类放在应用程序的根包中,例如com.baotrung.shop,组件扫描将从该包向下开始。所有其他组件应驻留在此包或子包中,事情会变得更容易,并且您需要更少的样板代码。将 Application 类放入其他组件的并行包(及以下)中(就像您所做的那样)将强制您设置组件扫描的路径,以查找这些(以及未来的)未按预期工作的组件。


查看完整回答
反对 回复 2024-01-25
  • 2 回答
  • 0 关注
  • 89 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信