亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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條經驗 獲得超13個贊

我使用 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 關注
  • 180 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號