Skip to content

Commit

Permalink
区分启动类名称
Browse files Browse the repository at this point in the history
  • Loading branch information
xlorne committed Nov 5, 2017
1 parent 1424078 commit 43c9a56
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 248 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ CREATE TABLE `t_test` (

demo1/demo2类型:

运行demo2下的DemoApplication,再运行demo1下的DemoApplication
运行demo2下的XXXDemoApplication,再运行demo1下的XXXDemoApplication

然后在浏览器访问http://127.0.0.1:8081/demo/save

Expand All @@ -278,7 +278,7 @@ demo1/demo2类型:

demo1/2/3/4/5类型:

运行demo5下的DemoApplication,再运行demo4下的DemoApplication,再运行demo3下的DemoApplication,再运行demo2下的DemoApplication,再运行demo1下的DemoApplication
分别运行demo5、demo4、demo3、demo2下的XXXDemoApplication,再运行demo1下的XXXDemoApplication

然后在浏览器访问http://127.0.0.1:8081/demo/save

Expand All @@ -287,4 +287,6 @@ demo1/2/3/4/5类型:
说明:demo1和demo3是消费者,默认在业务里添加了`int v = 100/0;`,demo3这行已注释,默认回滚,全部注释掉会提交事务。


XXXDemoApplication 就是对应不同demo版本下的启动类。

技术交流群:554855843
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;
Expand All @@ -19,10 +18,10 @@
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class DemoApplication {
public class JdbcDemo1Application {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
SpringApplication.run(JdbcDemo1Application.class, args);
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestDaoImpl implements TestDao {
@Override
public int save() {
String sql = "insert into t_test(name) values (?)";
return jdbcTemplate.update(sql,"hello");
return jdbcTemplate.update(sql,"jdbc-hello-1");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;
Expand All @@ -19,10 +18,10 @@
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class DemoApplication {
public class JdbcDemo2Application {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
SpringApplication.run(JdbcDemo2Application.class, args);
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestDaoImpl implements TestDao {
@Override
public int save() {
String sql = "insert into t_test(name) values (?)";
return jdbcTemplate.update(sql,"hello");
return jdbcTemplate.update(sql,"jdbc-hello-2");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;
Expand All @@ -19,10 +18,10 @@
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class DemoApplication {
public class JdbcDemo3Application {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
SpringApplication.run(JdbcDemo3Application.class, args);
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestDaoImpl implements TestDao {
@Override
public int save() {
String sql = "insert into t_test(name) values (?)";
return jdbcTemplate.update(sql,"hello");
return jdbcTemplate.update(sql,"jdbc-hello-3");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;
Expand All @@ -19,10 +18,10 @@
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class DemoApplication {
public class JdbcDemo4Application {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
SpringApplication.run(JdbcDemo4Application.class, args);
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestDaoImpl implements TestDao {
@Override
public int save() {
String sql = "insert into t_test(name) values (?)";
return jdbcTemplate.update(sql,"hello");
return jdbcTemplate.update(sql,"jdbc-hello-4");
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.example.demo;

import com.alibaba.druid.pool.DruidDataSource;
import com.lorne.tx.compensate.repository.CompensateDataSource;
import com.lorne.tx.db.LCNDataSourceProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

@EnableAutoConfiguration
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class JdbcDemo5Application {

public static void main(String[] args) {
SpringApplication.run(JdbcDemo5Application.class, args);
}

@Autowired
private Environment env;

@Bean
public DataSource dataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(env.getProperty("spring.datasource.url"));
dataSource.setUsername(env.getProperty("spring.datasource.username"));//用户名
dataSource.setPassword(env.getProperty("spring.datasource.password"));//密码
dataSource.setInitialSize(2);
dataSource.setMaxActive(20);
dataSource.setMinIdle(0);
dataSource.setMaxWait(60000);
dataSource.setValidationQuery("SELECT 1");
dataSource.setTestOnBorrow(false);
dataSource.setTestWhileIdle(true);
dataSource.setPoolPreparedStatements(false);

LCNDataSourceProxy dataSourceProxy = new LCNDataSourceProxy();
dataSourceProxy.setDataSource(dataSource);
dataSourceProxy.setMaxCount(10);
return dataSourceProxy;
}

@Bean
public CompensateDataSource compensateDataSource() {

DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(env.getProperty("spring.datasource.url"));
dataSource.setUsername(env.getProperty("spring.datasource.username"));//用户名
dataSource.setPassword(env.getProperty("spring.datasource.password"));//密码
dataSource.setInitialSize(1);
dataSource.setMaxActive(5);
dataSource.setMinIdle(0);
dataSource.setMaxWait(60000);
dataSource.setValidationQuery("SELECT 1");
dataSource.setTestOnBorrow(false);
dataSource.setTestWhileIdle(true);
dataSource.setPoolPreparedStatements(false);

CompensateDataSource compensateDataSource = new CompensateDataSource();
compensateDataSource.setDataSource(dataSource);
return compensateDataSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestDaoImpl implements TestDao {
@Override
public int save() {
String sql = "insert into t_test(name) values (?)";
return jdbcTemplate.update(sql,"hello");
return jdbcTemplate.update(sql,"jdbc-hello-5");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;
Expand All @@ -19,10 +18,10 @@
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class DemoApplication {
public class JpaDemo1Application {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
SpringApplication.run(JpaDemo1Application.class, args);
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int save() {
int rs2 = demo2Client.save();

Test test = new Test();
test.setName("hello1");
test.setName("jpa-hello-1");
int rs1 = testRepository.save(test).getId();

int v = 100/0;
Expand Down
Loading

0 comments on commit 43c9a56

Please sign in to comment.