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 并在其中使用了商店代碼依賴項??雌饋硐?:

TA貢獻1812條經驗 獲得超5個贊
我建議您清理/重組您的包層次結構以使其正常工作。
如果您將Application 類放在應用程序的根包中,例如com.baotrung.shop
,組件掃描將從該包向下開始。所有其他組件應駐留在此包或子包中,事情會變得更容易,并且您需要更少的樣板代碼。將 Application 類放入其他組件的并行包(及以下)中(就像您所做的那樣)將強制您設置組件掃描的路徑,以查找這些(以及未來的)未按預期工作的組件。
添加回答
舉報