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

我使用 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

}


12345678_0001
浏览 49回答 2
2回答

开满天机

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

ABOUTYOU

我建议您清理/重组您的包层次结构以使其正常工作。如果您将Application 类放在应用程序的根包中,例如com.baotrung.shop,组件扫描将从该包向下开始。所有其他组件应驻留在此包或子包中,事情会变得更容易,并且您需要更少的样板代码。将 Application 类放入其他组件的并行包(及以下)中(就像您所做的那样)将强制您设置组件扫描的路径,以查找这些(以及未来的)未按预期工作的组件。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java