-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fulan.zjf
committed
Nov 14, 2020
1 parent
29619db
commit 9d1aa68
Showing
66 changed files
with
1,815 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## 作用 | ||
主要提供了@Entity注解,该注解将Spring的Bean的scope定义为prototype,因为Domain Entity是有状态的,不能 | ||
进行多线程共享,所以必须是多实例的。 | ||
|
||
另外提供了DomainFactory辅助类,帮助应用创建Domain Entity。 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<name>cola-component-domain-starter</name> | ||
<groupId>com.alibaba.cola</groupId> | ||
<artifactId>cola-component-domain-starter</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<spring.boot.version>2.2.6.RELEASE</spring.boot.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- 测试包 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
58 changes: 58 additions & 0 deletions
58
...ponent-domain-starter/src/main/java/com/alibaba/cola/domain/ApplicationContextHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.alibaba.cola.domain; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* ApplicationContextHelper | ||
* | ||
* @author Frank Zhang | ||
* @date 2020-11-14 1:58 PM | ||
*/ | ||
@Component | ||
public class ApplicationContextHelper implements ApplicationContextAware { | ||
private static ApplicationContext applicationContext; | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
ApplicationContextHelper.applicationContext = applicationContext; | ||
} | ||
|
||
public static <T> T getBean(Class<T> targetClz) { | ||
T beanInstance = null; | ||
//优先按type查 | ||
try { | ||
beanInstance = (T)applicationContext.getBean(targetClz); | ||
} catch (Exception e) { | ||
} | ||
//按name查 | ||
if (beanInstance == null) { | ||
String simpleName = targetClz.getSimpleName(); | ||
//首字母小写 | ||
simpleName = Character.toLowerCase(simpleName.charAt(0)) + simpleName.substring(1); | ||
beanInstance = (T)applicationContext.getBean(simpleName); | ||
} | ||
if (beanInstance == null) { | ||
throw new RuntimeException("Component " + targetClz + " can not be found in Spring Container"); | ||
} | ||
return beanInstance; | ||
} | ||
|
||
public static Object getBean(String claz) { | ||
return ApplicationContextHelper.applicationContext.getBean(claz); | ||
} | ||
|
||
public static <T> T getBean(String name, Class<T> requiredType) { | ||
return ApplicationContextHelper.applicationContext.getBean(name, requiredType); | ||
} | ||
|
||
public static <T> T getBean(Class<T> requiredType, Object... params) { | ||
return ApplicationContextHelper.applicationContext.getBean(requiredType, params); | ||
} | ||
|
||
public static ApplicationContext getApplicationContext() { | ||
return applicationContext; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...mponent-domain-starter/src/main/java/com/alibaba/cola/domain/DomainAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.alibaba.cola.domain; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.EnableAspectJAutoProxy; | ||
|
||
/** | ||
* @ Description : | ||
* @ Author : Frank Zhang | ||
* @ CreateDate : 2020/11/09 | ||
* @ Version : 1.0 | ||
*/ | ||
@Configuration | ||
public class DomainAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(ApplicationContextHelper.class) | ||
public ApplicationContextHelper initCatchLogAspect() { | ||
return new ApplicationContextHelper(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ts/cola-component-domain-starter/src/main/java/com/alibaba/cola/domain/DomainFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.alibaba.cola.domain; | ||
|
||
/** | ||
* DomainFactory | ||
* | ||
* @author Frank Zhang | ||
* @date 2019-01-03 2:41 PM | ||
*/ | ||
public class DomainFactory { | ||
|
||
public static <T> T create(Class<T> entityClz){ | ||
return ApplicationContextHelper.getBean(entityClz); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...omponents/cola-component-domain-starter/src/main/java/com/alibaba/cola/domain/Entity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.alibaba.cola.domain; | ||
|
||
import org.springframework.beans.factory.config.ConfigurableBeanFactory; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* Entity, Entity Object is prototype and is not thread-safe | ||
* | ||
* @author Frank Zhang | ||
* @date 2019-01-03 2:53 PM | ||
*/ | ||
@Inherited | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
@Component | ||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) | ||
public @interface Entity { | ||
} |
1 change: 1 addition & 0 deletions
1
cola-components/cola-component-domain-starter/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration = com.alibaba.cola.domain.DomainAutoConfiguration |
22 changes: 22 additions & 0 deletions
22
...ents/cola-component-domain-starter/src/test/java/com/alibaba/cola/domain/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.alibaba.cola.domain; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* Application | ||
* | ||
* @author Frank Zhang | ||
* @date 2020-11-10 3:58 PM | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
|
||
Customer customer = DomainFactory.create(Customer.class); | ||
|
||
System.out.println("Customer purchase power score : " + customer.getPurchasePowerScore()); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ponents/cola-component-domain-starter/src/test/java/com/alibaba/cola/domain/Customer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.alibaba.cola.domain; | ||
|
||
import com.alibaba.cola.domain.Entity; | ||
|
||
import javax.annotation.Resource; | ||
|
||
/** | ||
* Customer | ||
* | ||
* @author Frank Zhang | ||
* @date 2020-11-14 2:43 PM | ||
*/ | ||
@Entity | ||
public class Customer { | ||
private String name; | ||
|
||
private Integer age; | ||
|
||
@Resource | ||
private PurchasePowerGateway purchasePowerGateway; | ||
|
||
public Integer getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(Integer age) { | ||
this.age = age; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Long getPurchasePowerScore(){ | ||
return purchasePowerGateway.getScore(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...-component-domain-starter/src/test/java/com/alibaba/cola/domain/PurchasePowerGateway.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.alibaba.cola.domain; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* PurchasePowerGateway | ||
* | ||
* @author Frank Zhang | ||
* @date 2020-11-14 2:45 PM | ||
*/ | ||
@Component | ||
public class PurchasePowerGateway { | ||
|
||
public Long getScore(){ | ||
return 96L; | ||
} | ||
} |
Empty file.
21 changes: 21 additions & 0 deletions
21
cola-components/cola-component-domain-starter/src/test/resources/logback-test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<configuration> | ||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/> | ||
|
||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> | ||
<charset>utf8</charset> | ||
</encoder> | ||
</appender> | ||
|
||
<!--rootLogger是默认的logger--> | ||
<root level="INFO"> | ||
<!--定义了两个appender,日志会通过往这两个appender里面写--> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
<!--应用日志--> | ||
<!--这个logger没有指定appender,它会继承root节点中定义的那些appender--> | ||
<logger name="com.alibaba.cola.domain" level="DEBUG"/> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## 作用 | ||
制定了DTO的相关规范,一是,为了复用;二是,使得应用层面的Logging和异常处理AOP成为可能。 | ||
|
||
关于Logging和异常处理的更多信息,请参考cola-component-catchlog-starter。 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## 作用 | ||
制定了Exception的相关规范,一是,为了复用;二是,使得应用层面的Logging和异常处理AOP成为可能。 | ||
|
||
实际上,对于应用系统而言,只有三种类型的异常: | ||
1. BizException:业务异常,有明确的业务语义,不需要记录Error日志,不需要Retry | ||
2. SysException:已知的系统异常,需要记录Error日志,可以Retry | ||
3. Exception:未知的其它异常,需要完整的Error Stack日志,可以Retry | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## 作用 | ||
该组件继承了老Cola Framework中的扩展点功能,旨在通过统一的扩展形式来支撑业务的变化。 | ||
|
||
## 原理 | ||
https://blog.csdn.net/significantfrank/article/details/100074716 | ||
|
||
## 使用介绍 | ||
参看测试代码`com.alibaba.cola.extension.test.ExtensionTest` | ||
|
Oops, something went wrong.