2 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
我使用 Spring Boot 并通過多個(gè)模塊進(jìn)行設(shè)計(jì)。下面是我的項(xiàng)目結(jié)構(gòu):
模塊商店核心:包名稱:com.baotrung.core.business 我設(shè)計(jì)了一些子包:模型,存儲(chǔ)庫,服務(wù)
行長:
<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>
類別服務(wù)
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);
}
類別 服務(wù)實(shí)施
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoriesRepository categoryRepository;
@Autowired
private LanguageRepository languageRepository;
@Autowired
private Mapper<Category,ReadableCategory> categoryReadableCategoryMapper;
//some method
@存儲(chǔ)庫
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
}
我還創(chuàng)建了模塊shopping-app p 并在其中使用了商店代碼依賴項(xiàng)。看起來像 :

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