1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

以2.2.1.BUILD-SNAPSHOT 为基准,适配Greenwich版本的Spring Cloud

This commit is contained in:
theonefx
2020-04-03 14:14:47 +08:00
parent e963a39bd4
commit 9444117f59
654 changed files with 7971 additions and 17442 deletions

View File

@@ -12,6 +12,10 @@
<artifactId>order-service</artifactId>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
@@ -29,9 +33,20 @@
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.31</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.examples;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.context.ApplicationContext;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
/**
@@ -33,55 +32,16 @@ import org.springframework.jdbc.core.JdbcTemplate;
@Configuration
public class DatabaseConfiguration {
private final ApplicationContext applicationContext;
public DatabaseConfiguration(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource storageDataSource() throws SQLException {
Environment env = applicationContext.getEnvironment();
String ip = env.getProperty("mysql.server.ip");
String port = env.getProperty("mysql.server.port");
String dbName = env.getProperty("mysql.db.name");
String userName = env.getProperty("mysql.user.name");
String password = env.getProperty("mysql.user.password");
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl(
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
druidDataSource.setUsername(userName);
druidDataSource.setPassword(password);
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
druidDataSource.setInitialSize(0);
druidDataSource.setMaxActive(180);
druidDataSource.setMaxWait(60000);
druidDataSource.setMinIdle(0);
druidDataSource.setValidationQuery("Select 'x' from DUAL");
druidDataSource.setTestOnBorrow(false);
druidDataSource.setTestOnReturn(false);
druidDataSource.setTestWhileIdle(true);
druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
druidDataSource.setMinEvictableIdleTimeMillis(25200000);
druidDataSource.setRemoveAbandoned(true);
druidDataSource.setRemoveAbandonedTimeout(1800);
druidDataSource.setLogAbandoned(true);
druidDataSource.setFilters("mergeStat");
return druidDataSource;
@Bean
@Primary
@ConfigurationProperties("spring.datasource")
public DataSource storageDataSource() {
return new DruidDataSource();
}
@Bean
public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) {
return new DataSourceProxy(druidDataSource);
}
@Bean
public JdbcTemplate jdbcTemplate(DataSourceProxy dataSourceProxy) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceProxy);
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("TRUNCATE TABLE order_tbl");

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,10 +19,30 @@ package com.alibaba.cloud.examples;
import java.io.Serializable;
public class Order implements Serializable {
/**
* id.
*/
public long id;
/**
* user id.
*/
public String userId;
/**
* commodity code.
*/
public String commodityCode;
/**
* count.
*/
public int count;
/**
* money.
*/
public int money;
@Override
@@ -30,4 +50,5 @@ public class Order implements Serializable {
return "Order{" + "id=" + id + ", userId='" + userId + '\'' + ", commodityCode='"
+ commodityCode + '\'' + ", count=" + count + ", money=" + money + '}';
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -46,13 +46,19 @@ import org.springframework.web.client.RestTemplate;
public class OrderController {
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
private static final String SUCCESS = "SUCCESS";
private static final String FAIL = "FAIL";
private static final String USER_ID = "U100001";
private static final String COMMODITY_CODE = "C00321";
private final JdbcTemplate jdbcTemplate;
private final RestTemplate restTemplate;
private Random random;
public OrderController(JdbcTemplate jdbcTemplate, RestTemplate restTemplate) {
@@ -127,4 +133,5 @@ public class OrderController {
ResponseEntity<String> response = restTemplate.postForEntity(url, request,
String.class);
}
}

View File

@@ -1,9 +1,29 @@
spring.application.name=order-service
server.port=18083
spring.cloud.nacos.discovery.server-addr=localhost:8848
mysql.server.ip=127.0.0.1
mysql.server.port=3306
mysql.db.name=demo
spring.datasource.name="orderDataSource"
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://xxx:3306/seata?useSSL=false&serverTimezone=UTC
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.druid.max-active=20
spring.datasource.druid.min-idle=2
spring.datasource.druid.initial-size=2
mysql.user.name=root
mysql.user.password=123456
seata.enabled=true
spring.cloud.alibaba.seata.tx-service-group=business-service
seata.service.vgroup-mapping.business-service=default
seata.service.grouplist.default=127.0.0.1:8091
seata.service.disable-global-transaction=false
## if use registry center
#seata.registry.type=nacos
#seata.registry.nacos.cluster=default
#seata.registry.nacos.server-addr=localhost
#
## if use config center
#seata.config.type=apollo
#seata.config.apollo.apollo-meta=http://192.168.1.204:8801
#seata.config.apollo.app-id=seata-server