Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-demo-single
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gic_demo
gic-demo-single
Commits
a818dd1b
Commit
a818dd1b
authored
Jul 17, 2019
by
朱瑞泽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
69fe1411
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
7 deletions
+126
-7
TestRun.java
...le-service/src/main/java/com/gic/demo/single/TestRun.java
+31
-7
applicationContext-db-only2.xml
...ervice/src/main/resources/applicationContext-db-only2.xml
+95
-0
No files found.
gic-demo-single-service/src/main/java/com/gic/demo/single/TestRun.java
View file @
a818dd1b
...
...
@@ -6,6 +6,9 @@ import org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.stereotype.Component
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
...
...
@@ -49,15 +52,36 @@ public class TestRun {
);
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"applicationContext-conf.xml"
);
TestRun
bean
=
applicationContext
.
getBean
(
TestRun
.
class
);
DemoStoreService
demoStoreService
=
applicationContext
.
getBean
(
DemoStoreService
.
class
);
public
void
test2
(
DemoStoreService
demoStoreService
)
{
System
.
out
.
println
(
"无事务"
);
bean
.
test
(
demoStoreService:
:
test1
);
demoStoreService
.
test1
(
"123"
);
System
.
out
.
println
(
"开启事务"
);
bean
.
test
(
demoStoreService:
:
test2
);
demoStoreService
.
test2
(
"456"
);
System
.
out
.
println
(
"只读事务"
);
bean
.
test
(
demoStoreService:
:
test3
);
demoStoreService
.
test3
(
"789"
);
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
,
IOException
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"applicationContext-conf.xml"
);
TestRun
bean
=
applicationContext
.
getBean
(
TestRun
.
class
);
DemoStoreService
demoStoreService
=
applicationContext
.
getBean
(
DemoStoreService
.
class
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
// String s = reader.readLine();
// System.out.println(s);
// System.out.println("无事务");
// bean.test(demoStoreService::test1);
// System.out.println("开启事务");
// bean.test(demoStoreService::test2);
// System.out.println("只读事务");
// bean.test(demoStoreService::test3);
while
(
true
)
{
String
s2
=
reader
.
readLine
();
System
.
out
.
println
(
s2
);
if
(
s2
.
equals
(
"exit"
))
{
System
.
exit
(
0
);
break
;
}
bean
.
test2
(
demoStoreService
);
}
}
}
gic-demo-single-service/src/main/resources/applicationContext-db-only2.xml
0 → 100644
View file @
a818dd1b
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:apollo=
"http://www.ctrip.com/schema/apollo"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.ctrip.com/schema/apollo
http://www.ctrip.com/schema/apollo.xsd"
>
<context:annotation-config
/>
<!--<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />-->
<!--<apollo:config/>-->
<apollo:config
namespaces=
"COMMON.4.0-jdbc"
/>
<bean
id=
"dataSource"
class=
"com.gic.commons.datasource.DruidDatasourceWrapper"
>
<!-- 基本属性 url、user、password -->
<!--<property name="url" value="${jdbc.url}" />-->
<!--<property name="username" value="${jdbc.username}" />-->
<!--<property name="password" value="${jdbc.password}" />-->
<property
name=
"databaseId"
value=
"${jdbc.databaseId}"
/>
<property
name=
"schema"
value=
"${jdbc.schema}"
/>
<property
name=
"jdbcOptions"
value=
"${jdbc.jdbcOptions}"
/>
<!-- 配置初始化大小、最小、最大 -->
<property
name=
"initialSize"
value=
"10"
/>
<property
name=
"minIdle"
value=
"1"
/>
<property
name=
"maxActive"
value=
"${jdbc.maxsize}"
/>
<property
name=
"defaultAutoCommit"
value=
"true"
/>
<property
name=
"removeAbandoned"
value=
"false"
/>
<!-- 打开removeAbandoned功能 -->
<property
name=
"removeAbandonedTimeout"
value=
"120"
/>
<!-- 1800秒,也就是30分钟 -->
<property
name=
"logAbandoned"
value=
"true"
/>
<!-- 关闭abanded连接时输出错误日志 -->
<!-- 配置获取连接等待超时的时间 -->
<property
name=
"maxWait"
value=
"0"
/>
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property
name=
"timeBetweenEvictionRunsMillis"
value=
"60000"
/>
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property
name=
"minEvictableIdleTimeMillis"
value=
"300000"
/>
<property
name=
"validationQuery"
value=
"SELECT 'x'"
/>
<property
name=
"testWhileIdle"
value=
"true"
/>
<property
name=
"testOnBorrow"
value=
"false"
/>
<property
name=
"testOnReturn"
value=
"false"
/>
<property
name=
"connectionInitSqls"
value=
"set names utf8mb4;"
/>
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 <property name="poolPreparedStatements"
value="false"/> <property name="maxPoolPreparedStatementPerConnectionSize"
value="20"/> -->
<!-- 配置监控统计拦截的filters <property name="filters" value="stat"/> -->
</bean>
<!--<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">-->
<!--<!– 基本属性 url、user、password –>-->
<!--<property name="url" value="${jdbc.url}" />-->
<!--<property name="username" value="${jdbc.username}" />-->
<!--<property name="password" value="${jdbc.password}" />-->
<!--<!– 配置初始化大小、最小、最大 –>-->
<!--<property name="initialSize" value="10" />-->
<!--<property name="minIdle" value="1" />-->
<!--<property name="maxActive" value="${jdbc.maxsize}" />-->
<!--<property name="removeAbandoned" value="true" /> <!– 打开removeAbandoned功能 –>-->
<!--<property name="removeAbandonedTimeout" value="120" /> <!– 1800秒,也就是30分钟 –>-->
<!--<property name="logAbandoned" value="true" /> <!– 关闭abanded连接时输出错误日志 –>-->
<!--<!– 配置获取连接等待超时的时间 –>-->
<!--<property name="maxWait" value="0" />-->
<!--<!– 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 –>-->
<!--<property name="timeBetweenEvictionRunsMillis" value="60000" />-->
<!--<!– 配置一个连接在池中最小生存的时间,单位是毫秒 –>-->
<!--<property name="minEvictableIdleTimeMillis" value="300000" />-->
<!--<property name="validationQuery" value="SELECT 'x'" />-->
<!--<property name="testWhileIdle" value="true" />-->
<!--<property name="testOnBorrow" value="false" />-->
<!--<property name="testOnReturn" value="false" />-->
<!--<!– 打开PSCache,并且指定每个连接上PSCache的大小 <property name="poolPreparedStatements" -->
<!--value="false"/> <property name="maxPoolPreparedStatementPerConnectionSize" -->
<!--value="20"/> –>-->
<!--<!– 配置监控统计拦截的filters <property name="filters" value="stat"/> –>-->
<!--</bean>-->
</beans>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment