1. 修复Web工程没有事务,2.修改数据源

This commit is contained in:
ascrutae 2016-07-19 07:33:28 +08:00
parent dec67ae0e4
commit f5acbaff87
5 changed files with 12 additions and 28 deletions

View File

@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.text.ParseException;
@ -21,6 +22,7 @@ import java.util.*;
* Created by xin on 16-4-25.
*/
@Service
@Transactional
public class AnalysisResultService implements IAnalysisResultService {
private Logger logger = LogManager.getLogger(AnalysisResultService.class);

View File

@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.sql.SQLException;
@ -18,6 +19,7 @@ import java.util.ArrayList;
import java.util.List;
@Service
@Transactional
public class CallChainTreeService implements ICallChainTreeService {
private Logger logger = LogManager.getLogger(CallChainTreeService.class);

View File

@ -10,6 +10,7 @@ import com.ai.cloud.skywalking.web.util.Constants;
import com.ai.cloud.skywalking.web.util.ReplaceAddressUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@ -22,6 +23,7 @@ import java.util.List;
* Created by xin on 16-3-30.
*/
@Service
@Transactional
public class TraceTreeService implements ITraceTreeService {
@Autowired

View File

@ -1,10 +1,9 @@
package com.ai.cloud.skywalking.web.util;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.sql.Connection;
@ -13,31 +12,14 @@ import java.sql.SQLException;
@Repository
public class DBConnectUtil {
@Value("#{configProperties['jdbc.url']}")
private String dbURL;
@Value("#{configProperties['jdbc.username']}")
private String dbUser;
@Value("#{configProperties['jdbc.password']}")
private String password;
@Value("#{configProperties['jdbc.driverClassName']}")
private String dbDriverClass;
private static Logger logger = LogManager.getLogger(DBConnectUtil.class);
@Autowired
private static HikariDataSource hikariDataSource;
public Connection getConnection() {
if (hikariDataSource == null) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(dbURL);
config.setUsername(dbUser);
config.setPassword(password);
config.setDriverClassName(dbDriverClass);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
hikariDataSource = new HikariDataSource(config);
}
try {
return hikariDataSource.getConnection();
} catch (SQLException e) {

View File

@ -13,15 +13,11 @@
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxTotal" value="${jdbc.maxTotal}"/>
<property name="maxIdle" value="${jdbc.maxIdle}"/>
<property name="maxWaitMillis" value="${jdbc.maxWaitMillis}"/>
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>
</bean>
<bean id="jdbcTemplate"
@ -42,7 +38,7 @@
</tx:advice>
<aop:config>
<aop:pointcut id="servicePointcut" expression="execution(* com.ai.cloud.service.inter.*.*(..))"/>
<aop:pointcut id="servicePointcut" expression="execution(* com.ai.cloud.skywalking.web.service.inter.*.*(..))"/>
<aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/>
</aop:config>