-
Notifications
You must be signed in to change notification settings - Fork 117
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
0 parents
commit 6631653
Showing
184 changed files
with
8,740 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
*.iml | ||
*/*.iml | ||
.idea/ | ||
|
||
.classpath | ||
.project | ||
.settings/ | ||
bin/ | ||
logs | ||
.DS_Store | ||
**.DS_Store |
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,6 @@ | ||
1. Spring cloud demo | ||
2. With eureka, ribbon feign hystrix | ||
3. All modules depend on spring-cloud-demo-starter, which configs the spring cloud. | ||
4. The heart beat time of eureka is configed to 5s, instead of 15s | ||
5. This code does not contain spring cloud config until now | ||
6. curl -H 'Accept:application/json' -X POST localhost:7004/shutdown |
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,20 @@ | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
*.iml | ||
*/*.iml | ||
.idea/ | ||
|
||
.classpath | ||
.project | ||
.settings/ | ||
bin/ | ||
logs | ||
.DS_Store | ||
**.DS_Store |
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,44 @@ | ||
<?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> | ||
|
||
<!-- created by harry, https://github.com/chxfantasy/spring-cloud-demo --> | ||
|
||
<groupId>com.tech.bixin</groupId> | ||
<artifactId>spring.cloud.account</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>spring.cloud.app</name> | ||
<description>spring.cloud, by Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>com.tech.bixin</groupId> | ||
<artifactId>spring.bixin.parent</artifactId> | ||
<version>1.0.0</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.tech.harry</groupId> | ||
<artifactId>spring.cloud.client</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.tech.harry</groupId> | ||
<artifactId>spring.cloud.starter</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
spring-cloud-account/src/main/java/spring/cloud/account/AccountApplication.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,34 @@ | ||
package spring.cloud.account; | ||
|
||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.feign.EnableFeignClients; | ||
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
|
||
@SpringBootApplication | ||
@EnableTransactionManagement | ||
@EnableScheduling | ||
@MapperScan("spring.cloud.account.dataaccess.mapper") | ||
@EnableDiscoveryClient | ||
@EnableFeignClients | ||
@EnableCircuitBreaker | ||
@EnableHystrixDashboard | ||
public class AccountApplication implements CommandLineRunner{ | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AccountApplication.class, args); | ||
} | ||
|
||
@Override | ||
public void run(String... arg0) throws Exception { | ||
//do something after spring-boot started | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
spring-cloud-account/src/main/java/spring/cloud/account/config/GlobalBeanConfig.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,46 @@ | ||
package spring.cloud.account.config; | ||
|
||
import org.springframework.cloud.context.config.annotation.RefreshScope; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import spring.cloud.account.config.interceptors.GlobalAspectInteceptor; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
@Configuration | ||
@EnableSwagger2 | ||
@RefreshScope | ||
public class GlobalBeanConfig { | ||
|
||
@Bean(name = "loggerInteceptor") | ||
public GlobalAspectInteceptor getLoggerInteceptor() { | ||
return new GlobalAspectInteceptor(); | ||
} | ||
|
||
@Bean | ||
public Docket createRestApi() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.apiInfo( getApiInfo() ) | ||
.host("127.0.0.1") | ||
.select() | ||
.apis(RequestHandlerSelectors.basePackage("spring.cloud.account")) | ||
.paths(PathSelectors.any()) | ||
.build(); | ||
} | ||
|
||
private ApiInfo getApiInfo() { | ||
return new ApiInfoBuilder() | ||
.title("spring-cloud-demo by harryChen, https://github.com/chxfantasy") | ||
.description("https://github.com/chxfantasy") | ||
.termsOfServiceUrl("https://github.com/chxfantasy") | ||
.contact("[email protected]") | ||
.version("1.0") | ||
.build(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
spring-cloud-account/src/main/java/spring/cloud/account/config/GlobalCacheHelper.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,49 @@ | ||
package spring.cloud.account.config; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
import spring.cloud.demo.cache.CacheService; | ||
import spring.cloud.demo.model.TraceIdHelper; | ||
|
||
import java.util.concurrent.ConcurrentSkipListSet; | ||
|
||
/** | ||
* Created by wangxiaohu on 2017/6/13. | ||
*/ | ||
@Component | ||
public class GlobalCacheHelper { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalCacheHelper.class); | ||
|
||
@Autowired private CacheService cacheService; | ||
private static ConcurrentSkipListSet<String> needToDeleteKeySet = new ConcurrentSkipListSet(); | ||
|
||
@Scheduled(fixedDelay = 1000) | ||
private void cacheDelete(){ | ||
if (!needToDeleteKeySet.isEmpty()){ | ||
String key = needToDeleteKeySet.first(); | ||
try { | ||
cacheService.deleteObjectByKey(key); | ||
LOGGER.info("traceId:{}, cacheDelete by GlobalCacheDelete, delete key {}", TraceIdHelper.getTraceId(), key); | ||
needToDeleteKeySet.remove(key); | ||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public static void putDeleteKeys( String key ) { | ||
if ( GlobalCacheHelper.needToDeleteKeySet.size() >= GlobalConstants.MAX_LIST_SIZE) { | ||
LOGGER.warn("traceId:{} , needToDeleteKey is over MAX_LIST_SIZE", TraceIdHelper.getTraceId()); | ||
} | ||
else { | ||
GlobalCacheHelper.needToDeleteKeySet.add(key); | ||
} | ||
|
||
// GlobalCacheDelete.needToDeleteKeySet.add(key); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
spring-cloud-account/src/main/java/spring/cloud/account/config/GlobalConstants.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,14 @@ | ||
package spring.cloud.account.config; | ||
|
||
/** | ||
* Created by wangxiaohu on 2017/6/19. | ||
*/ | ||
public class GlobalConstants { | ||
|
||
public static final String ACCOUNT_SERVICE_NAME = "spring.cloud.account"; | ||
|
||
public static final String BIZ_SERVICE_NAME = "spring.cloud.biz"; | ||
|
||
public static final int MAX_LIST_SIZE = 100000; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/spring/cloud/account/config/datasourceConfig/PrimarySourceConfiguration.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,29 @@ | ||
package spring.cloud.account.config.datasourceConfig; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.cloud.context.config.annotation.RefreshScope; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
|
||
import com.alibaba.druid.pool.DruidDataSource; | ||
|
||
@Configuration | ||
public class PrimarySourceConfiguration { | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix="spring.datasource") | ||
public DataSource dataSource() { | ||
DruidDataSource dataSource = (DruidDataSource) DataSourceBuilder.create().type(DruidDataSource.class).build(); | ||
return dataSource; | ||
} | ||
|
||
@Bean | ||
public DataSourceTransactionManager txManager( DataSource dataSource ) { | ||
return new DataSourceTransactionManager(dataSource); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...ount/src/main/java/spring/cloud/account/config/datasourceConfig/SessionFactoryConfig.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,54 @@ | ||
package spring.cloud.account.config.datasourceConfig; | ||
|
||
import java.util.Properties; | ||
|
||
import org.apache.ibatis.plugin.Interceptor; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.mybatis.spring.SqlSessionFactoryBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
|
||
import com.github.pagehelper.PageHelper; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
public class SessionFactoryConfig { | ||
|
||
@Value("${mybatis.mapper-locations}") | ||
private String mapperLocations; | ||
@Value("${mybatis.type-aliases-package}") | ||
private String typeAliasesPackage; | ||
@Value("${mybatis.config-location}") | ||
private String configLocation; | ||
|
||
@Bean | ||
public SqlSessionFactory sqlSessionFactory(@Autowired DataSource dataSource ) { | ||
try { | ||
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); | ||
sessionFactory.setDataSource(dataSource); | ||
sessionFactory.setTypeAliasesPackage(this.typeAliasesPackage); | ||
sessionFactory.setMapperLocations( new PathMatchingResourcePatternResolver().getResources(mapperLocations) ); | ||
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(configLocation)); | ||
|
||
PageHelper pageHelper = new PageHelper(); | ||
Properties props = new Properties(); | ||
props.setProperty("reasonable", "false"); | ||
props.setProperty("supportMethodsArguments", "true"); | ||
props.setProperty("returnPageInfo", "check"); | ||
props.setProperty("params", "count=countSql"); | ||
pageHelper.setProperties(props); | ||
|
||
sessionFactory.setPlugins(new Interceptor[] { pageHelper }); | ||
|
||
return sessionFactory.getObject(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
spring-cloud-account/src/main/java/spring/cloud/account/config/filters/FilterDemo.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,39 @@ | ||
package spring.cloud.account.config.filters; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.annotation.WebFilter; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.core.annotation.Order; | ||
@WebFilter(filterName="FilterDemo", urlPatterns={"/**"}) | ||
@Order(1) //当有多个filter时,指定filter的顺序 | ||
public class FilterDemo implements Filter{ | ||
private static final Logger LOGGER = LoggerFactory.getLogger( FilterDemo.class ); | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
LOGGER.debug(" filter demo "); | ||
chain.doFilter(request, response); | ||
} | ||
|
||
@Override | ||
public void init(FilterConfig arg0) throws ServletException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.