Top Related Projects
:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
🍬A set of tools that keep Java sweet.
The java implementation of Apache Dubbo. An RPC and microservice framework.
Spring Boot
🚀一个用来深入学习并实战 Spring Boot 的项目。
一个轻量级 Java 权限认证框架,让鉴权变得简单、优雅!—— 登录认证、权限认证、分布式Session会话、微服务网关鉴权、单点登录、OAuth2.0
Quick Overview
COLA (Clean Object-oriented and Layered Architecture) is an application architecture and development framework designed by Alibaba. It aims to help developers build enterprise-level applications with a clean, scalable, and maintainable structure. COLA provides a set of best practices and tools for implementing domain-driven design (DDD) principles in Java applications.
Pros
- Promotes clean architecture and separation of concerns
- Provides a standardized approach to building enterprise applications
- Includes code generators and archetypes to speed up development
- Integrates well with popular Java frameworks like Spring Boot
Cons
- Steep learning curve for developers unfamiliar with DDD concepts
- May be overkill for smaller projects or simple applications
- Limited documentation and resources in English
- Requires adherence to specific architectural patterns, which may not suit all project needs
Code Examples
- Defining a Command:
@Data
@EqualsAndHashCode(callSuper = false)
public class PlaceOrderCmd extends Command {
private String customerName;
private String productId;
private int quantity;
}
- Implementing a CommandExecutor:
@Component
public class PlaceOrderCmdExe implements CommandExecutor<PlaceOrderCmd, OrderDTO> {
@Resource
private OrderRepository orderRepository;
@Override
public OrderDTO execute(PlaceOrderCmd cmd) {
Order order = new Order(cmd.getCustomerName(), cmd.getProductId(), cmd.getQuantity());
orderRepository.save(order);
return OrderAssembler.toDTO(order);
}
}
- Using the COLA EventBus:
@Component
public class OrderCreatedEventHandler implements EventHandler<OrderCreatedEvent> {
@Resource
private EventBus eventBus;
@Override
public void execute(OrderCreatedEvent event) {
// Handle the event
System.out.println("Order created: " + event.getOrderId());
// Publish another event if needed
eventBus.fire(new NotifyCustomerEvent(event.getOrderId()));
}
}
Getting Started
To start using COLA in your project:
- Add the COLA dependencies to your
pom.xml
:
<dependency>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-component-domain-starter</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-component-exception</artifactId>
<version>4.3.1</version>
</dependency>
- Use COLA archetypes to generate project structure:
mvn archetype:generate \
-DgroupId=com.example \
-DartifactId=my-cola-project \
-Dversion=1.0.0-SNAPSHOT \
-Dpackage=com.example \
-DarchetypeGroupId=com.alibaba.cola \
-DarchetypeArtifactId=cola-framework-archetype-web \
-DarchetypeVersion=4.3.1
- Implement your domain logic following COLA's architectural guidelines.
Competitor Comparisons
:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
Pros of Seata
- Focused on distributed transaction management, providing a comprehensive solution for microservices
- Supports multiple transaction modes (AT, TCC, SAGA, XA) for different scenarios
- Integrates well with popular frameworks and cloud-native environments
Cons of Seata
- Steeper learning curve due to its specialized nature in distributed transactions
- May introduce additional complexity and overhead in simpler application architectures
COLA Pros
- Provides a complete application architecture framework for complex business systems
- Emphasizes domain-driven design (DDD) principles and clean architecture
- Offers a more holistic approach to application development beyond just transaction management
COLA Cons
- Less specialized in distributed transaction management compared to Seata
- May be overkill for smaller or less complex applications
Code Comparison
Seata (Transaction Management):
@GlobalTransactional
public void businessMethod() {
// Business logic with distributed transaction
}
COLA (Application Architecture):
@Command
public class CreateOrderCmd extends Command {
// Command object for creating an order
}
Both projects serve different primary purposes, with Seata focusing on distributed transactions and COLA providing a comprehensive application architecture framework. The choice between them depends on the specific needs of the project, with Seata being more suitable for complex distributed transaction scenarios and COLA for overall application structure and design.
🍬A set of tools that keep Java sweet.
Pros of Hutool
- Lightweight and easy to use, with a focus on utility functions
- Extensive collection of tools covering various Java development needs
- Active community and frequent updates
Cons of Hutool
- Less structured approach for large-scale application architecture
- Limited support for complex business logic and domain-driven design
- May require additional frameworks for comprehensive enterprise applications
Code Comparison
Hutool example:
String result = StrUtil.format("Hello, {}!", "World");
DateTime dateTime = DateUtil.parse("2023-05-15");
String md5 = SecureUtil.md5("password");
COLA example:
@Command
public class PlaceOrderCmd extends Command {
private String customerId;
private List<OrderItemDTO> orderItems;
}
public OrderDTO placeOrder(PlaceOrderCmd cmd) {
// Business logic implementation
}
Summary
Hutool is a versatile utility library for Java developers, offering a wide range of tools for common tasks. It excels in simplifying day-to-day coding challenges but may not provide the architectural guidance needed for large-scale enterprise applications. COLA, on the other hand, focuses on providing a structured approach to building complex business applications, emphasizing clean architecture and domain-driven design principles. While Hutool is more suitable for quick solutions and smaller projects, COLA is better suited for enterprise-level applications with intricate business logic.
The java implementation of Apache Dubbo. An RPC and microservice framework.
Pros of Dubbo
- Mature and widely adopted high-performance RPC framework
- Extensive service governance features (load balancing, routing, clustering)
- Strong community support and active development
Cons of Dubbo
- Primarily focused on RPC, less comprehensive for full application architecture
- Steeper learning curve for developers new to distributed systems
- More complex setup and configuration compared to simpler frameworks
Code Comparison
COLA (Clean Object-Oriented and Layered Architecture):
@Component
public class CustomerServiceImpl implements CustomerService {
@Resource
private CustomerMapper customerMapper;
public CustomerDTO getCustomer(String customerId) {
CustomerDO customerDO = customerMapper.getById(customerId);
return CustomerAssembler.toDTO(customerDO);
}
}
Dubbo:
@Service(version = "1.0.0")
public class CustomerServiceImpl implements CustomerService {
@Autowired
private CustomerMapper customerMapper;
public CustomerDTO getCustomer(String customerId) {
CustomerDO customerDO = customerMapper.getById(customerId);
return CustomerAssembler.toDTO(customerDO);
}
}
While both examples show similar service implementations, Dubbo uses its own @Service
annotation for RPC service exposure, whereas COLA follows a more standard Spring-based approach. Dubbo's focus on RPC is evident, while COLA provides a broader architectural framework.
Spring Boot
Pros of Spring Boot
- Extensive ecosystem with a wide range of starter dependencies
- Robust auto-configuration capabilities
- Large and active community support
Cons of Spring Boot
- Can be heavyweight for simple applications
- Learning curve for advanced features and customizations
Code Comparison
Spring Boot:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
COLA:
@ColaApplication
public class Application {
public static void main(String[] args) {
ColaApplication.run(Application.class, args);
}
}
Key Differences
- COLA focuses on Clean Architecture and Domain-Driven Design principles
- Spring Boot provides a more general-purpose framework for various application types
- COLA offers a structured approach to organizing business logic and application layers
- Spring Boot has more extensive documentation and third-party integrations
Use Cases
- Spring Boot: Ideal for rapid prototyping, microservices, and enterprise applications
- COLA: Well-suited for complex domain logic and large-scale enterprise applications
Community and Support
- Spring Boot has a larger community and more resources available
- COLA is backed by Alibaba and gaining traction in enterprise environments
Learning Curve
- Spring Boot: Easier to get started, but can become complex with advanced features
- COLA: Requires understanding of Clean Architecture and DDD concepts
🚀一个用来深入学习并实战 Spring Boot 的项目。
Pros of spring-boot-demo
- More comprehensive coverage of Spring Boot features and integrations
- Easier to understand for beginners due to its modular structure
- Regularly updated with new Spring Boot versions and features
Cons of spring-boot-demo
- Lacks a cohesive architectural framework compared to COLA
- May not be as suitable for large-scale enterprise applications
- Does not provide as much guidance on application layering and design principles
Code Comparison
COLA example (Domain-Driven Design approach):
@Data
@Entity
public class Customer extends BaseEntity {
private String name;
private String email;
// ...
}
spring-boot-demo example (Simple POJO approach):
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
private Long id;
private String name;
private Integer age;
// ...
}
Summary
COLA provides a more structured approach for building enterprise applications using Domain-Driven Design principles, while spring-boot-demo offers a wider range of Spring Boot examples and integrations. COLA is better suited for large-scale projects requiring a robust architecture, whereas spring-boot-demo is more accessible for developers learning Spring Boot or implementing smaller applications.
一个轻量级 Java 权限认证框架,让鉴权变得简单、优雅!—— 登录认证、权限认证、分布式Session会话、微服务网关鉴权、单点登录、OAuth2.0
Pros of Sa-Token
- Lightweight and easy to integrate, focusing specifically on authentication and authorization
- Extensive documentation and examples for various use cases
- Supports multiple login methods and session management
Cons of Sa-Token
- Limited scope compared to COLA's comprehensive architecture
- May require additional libraries for full application development
- Less emphasis on domain-driven design principles
Code Comparison
Sa-Token authentication example:
// Login
StpUtil.login(10001);
// Get login ID
String loginId = StpUtil.getLoginId();
// Check login status
boolean isLogin = StpUtil.isLogin();
COLA architecture example:
@Component
public class CustomerServiceImpl implements CustomerServiceI {
@Resource
private CustomerMapper customerMapper;
public CustomerDTO getCustomer(String customerId) {
Customer customer = customerMapper.getById(customerId);
return CustomerAssembler.toDTO(customer);
}
}
Sa-Token focuses on authentication and authorization, providing a simple API for managing user sessions. COLA, on the other hand, offers a more comprehensive architecture for building enterprise applications, emphasizing domain-driven design and clean architecture principles.
While Sa-Token excels in its specific domain, COLA provides a broader framework for structuring entire applications. The choice between the two depends on the project's scope and requirements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
𥤠COLA v5
COLA æ¯ Clean Object-Oriented and Layered Architectureç缩åï¼ä»£è¡¨âæ´æ´é¢å对象åå±æ¶æâã ç®åCOLAå·²ç»åå±å°COLA v5ã
- æ³äºè§£æ´å¤COLAä¿¡æ¯ï¼è¯·å ³æ³¨å¾®ä¿¡å ¬ä¼å·ï¼
- æ³äºè§£æ´å¤COLAèåçæ äºï¼è¯·æ¯ææçæ°ä¹¦ãç¨åºåçåºå±æç»´ã
COLAå为两个é¨åï¼COLAæ¶æåCOLAç»ä»¶ã
ä¸ãCOLAæ¶æ
COLA æ¦è¿°
æ¶æçæä¹ å°±æ¯ è¦ç´ ç»æï¼
- è¦ç´ æ¯ ç»ææ¶æçéè¦å ç´ ï¼
- ç»æ æ¯ è¦ç´ ä¹é´çå ³ç³»ã
è åºç¨æ¶æçæä¹ å°±å¨äº
- å®ä¹ä¸å¥è¯å¥½çç»æï¼
- æ²»çåºç¨å¤æ度ï¼éä½ç³»ç»çµå¼ï¼
- ä»éå¿æ欲çæ··ä¹±ç¶æï¼èµ°åäºäºææ¡çæåºç¶æã
COLAæ¶æå°±æ¯ä¸ºæ¤èçï¼å ¶æ ¸å¿è责就æ¯å®ä¹è¯å¥½çåºç¨ç»æï¼æä¾æä½³åºç¨æ¶æçæä½³å®è·µãéè¿ä¸ææ¢ç´¢ï¼æ们åç°è¯å¥½çåå±ç»æï¼è¯å¥½çå ç»æå®ä¹ï¼å¯ä»¥å¸®å©æ们治çæ··ä¹±ä¸å ªçä¸å¡åºç¨ç³»ç»ã
ç»è¿å¤æ¬¡è¿ä»£ï¼æ们å®ä¹åºäºç¸å¯¹ç¨³å®ãå¯é çåºç¨æ¶æï¼
COLA Archetypes
好çåºç¨æ¶æï¼é½éµå¾ªä¸äºå ±å模å¼ï¼ä¸ç®¡æ¯å 边形æ¶æãæ´è±åæ¶æãæ´æ´æ¶æãè¿æ¯COLAæ¶æï¼é½æå¡ä»¥ä¸å¡ä¸ºæ ¸å¿ï¼è§£è¦å¤é¨ä¾èµï¼å离ä¸å¡å¤æ度åææ¯å¤æ度çã
COLAæ¶æåºå«äºè¿äºæ¶æçå°æ¹ï¼å¨äºé¤äºææ³ä¹å¤ï¼æ们è¿æä¾äºå¯è½å°çå·¥å ·åå®è·µæ导ã
为äºè½å¤å¿«éå建满足COLAæ¶æçåºç¨ï¼æ们æä¾äºä¸¤ä¸ªarchetype
ï¼ä½äºcola-archetypes
ç®å½ä¸ï¼
cola-archetype-service
ï¼ç¨æ¥å建纯å端æå¡çarchetype
ãcola-archetype-web
ï¼ç¨æ¥å建adapter
åå端æå¡ä¸ä½çweb
åºç¨archetype
ã
äºãCOLAç»ä»¶
æ¤å¤ï¼æ们è¿æä¾äºä¸äºé常æç¨çéç¨ç»ä»¶ï¼è¿äºç»ä»¶å¯ä»¥å¸®å©æ们æåç åæçã
è¿äºåè½ç»ä»¶è¢«æ¶æ¢å¨cola-components
ç®å½ä¸é¢ãå°ç®å为æ¢ï¼æ们已ç»æ²æ·äºä»¥ä¸ç»ä»¶ï¼
ç»ä»¶å称 | åè½ | ä¾èµ |
---|---|---|
cola-component-dto | å®ä¹äºDTO æ ¼å¼ï¼å
æ¬å页 | æ |
cola-component-exception | å®ä¹äºå¼å¸¸æ ¼å¼ï¼ 主è¦æ BizException åSysException | æ |
cola-component-statemachine | ç¶ææºç»ä»¶ | æ |
cola-component-domain-starter | Spring æ管çé¢åå®ä½ç»ä»¶ | æ |
cola-component-catchlog-starter | å¼å¸¸å¤çåæ¥å¿ç»ä»¶ | exception ãdto ç»ä»¶ |
cola-component-extension-starter | æ©å±ç¹ç»ä»¶ | æ |
cola-component-test-container | æµè¯å®¹å¨ç»ä»¶ | æ |
ä¸ãå¦ä½ä½¿ç¨COLA
1. å建åºç¨
æ§è¡ä»¥ä¸å½ä»¤ï¼
mvn archetype:generate \
-DgroupId=com.alibaba.cola.demo.web \
-DartifactId=demo-web \
-Dversion=1.0.0-SNAPSHOT \
-Dpackage=com.alibaba.demo \
-DarchetypeArtifactId=cola-framework-archetype-web \
-DarchetypeGroupId=com.alibaba.cola \
-DarchetypeVersion=5.0.0
å½ä»¤æ§è¡æåçè¯ï¼ä¼çå°å¦ä¸çåºç¨ä»£ç ç»æï¼
2. è¿è¡åºç¨
- å¨
项ç®
ç®å½ä¸è¿è¡mvn install
ï¼å¦æä¸æ³è¿è¡æµè¯ï¼å¯ä»¥å ä¸-DskipTests
åæ°ï¼ã - è¿å
¥
start
ç®å½ï¼æ§è¡mvn spring-boot:run
ã
è¿è¡æåçè¯ï¼å¯ä»¥çå°SpringBoot
å¯å¨æåççé¢ã - çæçåºç¨ä¸ï¼å·²ç»å®ç°äºä¸ä¸ªç®åç
Rest
请æ±ï¼å¯ä»¥å¨æµè§å¨ä¸è¾å ¥ http://localhost:8080/helloworld è¿è¡æµè¯ã
å¦æè¦çæä¸æ¯web
å·¥ç¨èæ¯service
å·¥ç¨ä¹ç±»ä¼¼ï¼æ§è¡çæ¯ä¸é¢çå½ä»¤ï¼
mvn archetype:generate \
-DgroupId=com.alibaba.cola.demo.service \
-DartifactId=demo-service \
-Dversion=1.0.0-SNAPSHOT \
-Dpackage=com.alibaba.demo \
-DarchetypeArtifactId=cola-framework-archetype-service \
-DarchetypeGroupId=com.alibaba.cola \
-DarchetypeVersion=5.0.0
çæ¬è¿ä»£
5.0.0 çæ¬
- æ¯æjdk17åSpringBoot 3.x
- å¢å cola-archetype-lightï¼æ¯ææ°çåºäºpackageè½»é级åå±æ¶æ
- å¢å cola-component-unittestç»ä»¶ï¼æ¯ææ°çåå æµè¯
- å¢å¼ºcola-component-test-containerç»ä»¶ï¼æ¯æJunit5çExtension
4.0.0 çæ¬
https://blog.csdn.net/significantfrank/article/details/110934799
3.1.0 çæ¬
https://blog.csdn.net/significantfrank/article/details/109529311
- è¿ä¸æ¥ç®åäº
cola-core
ï¼åªä¿çäºæ©å±è½åã - å°
exception
ä»cola-core
ç§»å ¥å°cola-common
ã - 对
archetype
ä¸çåå é»è¾è¿è¡éæï¼æ¹ææç §domain
åååã - å°
cola-archetype-web
ä¸çcontroller
æ¹å为adapter
ï¼ä¸ºäºå¼åºå 边形æ¶æçå½åã
3.0.0 çæ¬
https://blog.csdn.net/significantfrank/article/details/106976804
2.0.0 çæ¬
https://blog.csdn.net/significantfrank/article/details/100074716
1.0.0 çæ¬
https://blog.csdn.net/significantfrank/article/details/85785565
Top Related Projects
:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
🍬A set of tools that keep Java sweet.
The java implementation of Apache Dubbo. An RPC and microservice framework.
Spring Boot
🚀一个用来深入学习并实战 Spring Boot 的项目。
一个轻量级 Java 权限认证框架,让鉴权变得简单、优雅!—— 登录认证、权限认证、分布式Session会话、微服务网关鉴权、单点登录、OAuth2.0
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot