From 286ede4df9a94a033eb3f9edc1ded901d316cdde Mon Sep 17 00:00:00 2001 From: RenKaiGe-Office Date: Thu, 17 May 2018 14:53:57 +0800 Subject: [PATCH] =?UTF-8?q?1:=E6=B7=BB=E5=8A=A0spring-data-redis1.7.1?= =?UTF-8?q?=E7=9B=B8=E5=85=B3jar=E5=8F=8A=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=202:=E6=B7=BB=E5=8A=A0fastdfs=E7=9A=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3jar=E5=8F=8A=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=203:?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9F=90=E4=BA=9B=E7=B3=BB=E7=BB=9F=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E9=A1=B9=E7=9B=AE=E5=90=8D=E7=A7=B0=E4=B8=BA?= =?UTF-8?q?maat=5Fservice(=E6=9C=89=E4=BA=9B=E7=B3=BB=E7=BB=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E9=87=8C=E9=9D=A2=E7=9A=84=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=90=8D=E7=A7=B0=E6=B2=A1=E6=9C=89=E6=94=B9=E8=BF=87?= =?UTF-8?q?=E6=9D=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .project | 13 +- .settings/org.eclipse.core.resources.prefs | 2 +- .settings/org.eclipse.wst.common.component | 8 +- pom.xml | 138 ++++++++++-------- .../nis/datasource/DynamicJedisDataBase.java | 28 ++++ .../restful/ConfigSourcesController.java | 32 +++- .../controller/restful/FastDFSController.java | 110 ++++++++++++++ .../com/nis/web/dao/impl/BaseRedisDao.java | 13 ++ .../com/nis/web/service/fdfs/FastDFSFile.java | 80 ++++++++++ .../com/nis/web/service/fdfs/FileManager.java | 108 ++++++++++++++ .../web/service/fdfs/FileManagerConfig.java | 29 ++++ .../web/service/restful/TestRedisService.java | 14 ++ .../service/restful/TestRedisServiceimpl.java | 36 +++++ .../resources/applicationContext-redis.xml | 52 +++++++ src/main/resources/fastdfs-client.properties | 14 ++ src/main/resources/fdfs_client.conf | 10 ++ src/main/resources/jdbc.properties | 19 ++- src/main/resources/redis.properties | 10 ++ src/main/resources/spring-mvc.xml | 109 ++++++++------ src/main/webapp/WEB-INF/web.xml | 10 +- src/test/java/com/nis/test/RedisTest.java | 31 ++++ 21 files changed, 739 insertions(+), 127 deletions(-) create mode 100644 src/main/java/com/nis/datasource/DynamicJedisDataBase.java create mode 100644 src/main/java/com/nis/web/controller/restful/FastDFSController.java create mode 100644 src/main/java/com/nis/web/dao/impl/BaseRedisDao.java create mode 100644 src/main/java/com/nis/web/service/fdfs/FastDFSFile.java create mode 100644 src/main/java/com/nis/web/service/fdfs/FileManager.java create mode 100644 src/main/java/com/nis/web/service/fdfs/FileManagerConfig.java create mode 100644 src/main/java/com/nis/web/service/restful/TestRedisService.java create mode 100644 src/main/java/com/nis/web/service/restful/TestRedisServiceimpl.java create mode 100644 src/main/resources/applicationContext-redis.xml create mode 100644 src/main/resources/fastdfs-client.properties create mode 100644 src/main/resources/fdfs_client.conf create mode 100644 src/main/resources/redis.properties create mode 100644 src/test/java/com/nis/test/RedisTest.java diff --git a/.project b/.project index 7e4d140..e4f82a8 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - gk + maat_service @@ -30,6 +30,16 @@ + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.springframework.ide.eclipse.boot.validation.springbootbuilder + + + org.eclipse.m2e.core.maven2Builder @@ -37,6 +47,7 @@ + org.springframework.ide.eclipse.core.springnature org.eclipse.jem.workbench.JavaEMFNature org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.jdt.core.javanature diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 4531ab9..26ec8b2 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -5,10 +5,10 @@ encoding//src/main/resources/jdbc.properties=UTF-8 encoding//src/main/resources/log4j.properties=UTF-8 encoding//src/main/resources/matt.properties=UTF-8 encoding//src/main/resources/nis.properties=UTF-8 +encoding//src/main/resources/redis.properties=UTF-8 encoding//src/main/resources/table.properties=UTF-8 encoding//src/main/webapp/WEB-INF/include/header.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/tlds/fns.tld=UTF-8 encoding//src/main/webapp/WEB-INF/views/letter/process/errorView.jsp=UTF-8 encoding//src/main/webapp/static/common/jeesite.css=UTF-8 encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index e62df70..fa4931f 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,10 +1,12 @@ - + - - + + + + diff --git a/pom.xml b/pom.xml index 18dae5f..cffb483 100644 --- a/pom.xml +++ b/pom.xml @@ -14,9 +14,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 war - gk + maat_service com.nis.springmvc - gk + maat_service 0.0.1-SNAPSHOT @@ -37,6 +37,11 @@ + + + + + @@ -64,19 +69,19 @@ - - - org.mybatis.generator - mybatis-generator-maven-plugin - [1.3.2,) - - generate - - - - - - + + + + + + + + + + + + + UTF-8 @@ -84,52 +89,47 @@ - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.3.2 - - - Generate MyBatis Artifacts - - generate - - + + + + + + + + + + + - - - true - true - + + + + + - + - - mysql - mysql-connector-java - 5.1.36 - + + + + + - - org.mybatis - mybatis - ${mybatis.version} - + + + + + - - org.mybatis.generator - mybatis-generator-core - 1.3.2 - + + + + + + - - - - - - + org.mortbay.jetty @@ -159,6 +159,14 @@ + + + + + + + + 4.1.7.RELEASE @@ -173,15 +181,15 @@ 1.4.7 3.9 1.7.7 + 2.9.0 + 1.7.1.RELEASE UTF-8 - - junit junit - 4.11 + 4.12 test @@ -304,7 +312,7 @@ redis.clients jedis - 2.9.0 + ${jedis.version} @@ -610,7 +618,19 @@ httpclient 4.4 + + + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + + + + org.csource + fastdfs-client-java + 1.27-SNAPSHOT + - diff --git a/src/main/java/com/nis/datasource/DynamicJedisDataBase.java b/src/main/java/com/nis/datasource/DynamicJedisDataBase.java new file mode 100644 index 0000000..9501616 --- /dev/null +++ b/src/main/java/com/nis/datasource/DynamicJedisDataBase.java @@ -0,0 +1,28 @@ +package com.nis.datasource; + +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; + +import com.nis.web.service.SpringContextHolder; + +/** + * + *

Title: DynamicJedisDataBase

+ *

Description: 设置使用redis的哪个数据库

+ *

Company: IIE

+ * @author rkg + * @date 2018年5月17日 + * + */ +public class DynamicJedisDataBase { + /** + * 设置redisTemplate使用哪个数据库,默认使用的是数据库0 + * @param index + * @param redisTemplate + */ + public static void setRedisDataBase(int index, RedisTemplate redisTemplate) { + JedisConnectionFactory connectionFactory = SpringContextHolder.getBean("connectionFactory"); + connectionFactory.setDatabase(index); + redisTemplate.setConnectionFactory(connectionFactory); + } +} diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java index 1b6645e..51c346f 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -26,6 +26,7 @@ import com.nis.util.StringUtils; import com.nis.web.controller.BaseRestController; import com.nis.web.service.SaveRequestLogThread; import com.nis.web.service.ServicesRequestLogService; +import com.nis.web.service.restful.TestRedisService; import com.nis.web.service.restful.ConfigSourcesService; import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; @@ -48,6 +49,22 @@ public class ConfigSourcesController extends BaseRestController { @Autowired protected ServicesRequestLogService servicesRequestLogService; + @Autowired + TestRedisService testRedisServiceimpl; + + @RequestMapping(value = "/save", method = RequestMethod.GET) + @ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller") + @ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true) + public String testRedis() { + try { + testRedisServiceimpl.saveConfigCompile(); + return "ok"; + } catch (Exception e) { + e.printStackTrace(); + } + return "false"; + } + @RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST) @ApiOperation(value = "业务配置存储", httpMethod = "POST", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储") @ApiParam(value = "业务配置数据源", name = "configSource", required = true) @@ -123,14 +140,16 @@ public class ConfigSourcesController extends BaseRestController { checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2); String msg = ""; ConfigCompile compile = configSource.getConfigCompileList().get(0); - if(StringUtil.isEmpty(compile.getGroupRelationList())&&StringUtil.isEmpty(compile.getIpRegionList())&&StringUtil.isEmpty(compile.getStrRegionList())&&StringUtil.isEmpty(compile.getNumRegionList())){ + if (StringUtil.isEmpty(compile.getGroupRelationList()) && StringUtil.isEmpty(compile.getIpRegionList()) + && StringUtil.isEmpty(compile.getStrRegionList()) + && StringUtil.isEmpty(compile.getNumRegionList())) { msg = configSourcesService.updateByJDBCThread3(thread, start, configSource.getConfigCompileList(), - configSource.getOpTime(), sb); - }else{ + configSource.getOpTime(), sb); + } else { msg = configSourcesService.updateByJDBCThread12(thread, start, configSource.getConfigCompileList(), - configSource.getOpTime(), sb); + configSource.getOpTime(), sb); } - + if (msg.equals("error")) { String errorCode = ""; Exception exception = ConfigSourcesService.getMsgList().get(0); @@ -240,7 +259,8 @@ public class ConfigSourcesController extends BaseRestController { } } - Map throwExceptionInfo = OracleErrorCodeUtil.throwExceptionInfo(errorCode); + Map throwExceptionInfo = OracleErrorCodeUtil + .throwExceptionInfo(errorCode); for (int errorNum : throwExceptionInfo.keySet()) { if (errorNum == 998) { thread.setExceptionInfo(e.toString()); diff --git a/src/main/java/com/nis/web/controller/restful/FastDFSController.java b/src/main/java/com/nis/web/controller/restful/FastDFSController.java new file mode 100644 index 0000000..a4dce9b --- /dev/null +++ b/src/main/java/com/nis/web/controller/restful/FastDFSController.java @@ -0,0 +1,110 @@ +package com.nis.web.controller.restful; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.csource.common.MyException; +import org.csource.common.NameValuePair; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; + +import com.nis.web.service.fdfs.FastDFSFile; +import com.nis.web.service.fdfs.FileManager; + +/** + *

Title: FastDFSController.java

+ *

Description: fastdfs测试controller

+ *

Company: IIE

+ * @author rkg + * @date 2018年5月16日 + * + */ +@Controller +public class FastDFSController { + public static void main(String[] args) { + String path = new FastDFSController().testAdd(); + //String path = "M00/00/01/CgAGwFr786aAegOQAADz3NN2rlY283.jpg"; + new FastDFSController().testDelete(path); + + } + + public void testDelete(String filePath) { + filePath = filePath.substring(filePath.indexOf("group")); + String groupName=filePath.substring(0,filePath.indexOf("/")); + filePath=filePath.substring(filePath.indexOf("/")+1); + Integer a = FileManager.delete_file(groupName, filePath); + System.out.println(a); + } + + public String testAdd() { + String filePath = "d:/1.jpg"; + File file = new File(filePath); + String fileName = file.getName(); + String ext = fileName.substring(fileName.lastIndexOf(".") + 1); + NameValuePair[] meta_list = new NameValuePair[4]; + meta_list[0] = new NameValuePair("fileName", fileName); + meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.length())); + meta_list[2] = new NameValuePair("fileExt", ext); + meta_list[3] = new NameValuePair("fileAuthor", "rkg"); + String successFilePath = FileManager.upload(new FastDFSFile(getByte(file), ext), null); + System.out.println("上传成功返回的路径是" + successFilePath); + return successFilePath; + } + + private byte[] getByte(File file) { + byte[] bf = null; + try { + InputStream fis = new FileInputStream(file); + bf = new byte[fis.available()]; + fis.read(bf); + } catch (Exception e) { + e.printStackTrace(); + } + return bf; + } + + @ResponseBody + @RequestMapping(value = "/add", method = RequestMethod.POST) + // public String add(@Validated User user, MultipartFile attach, + // HttpServletRequest request) + public String add(MultipartFile attach, HttpServletRequest request) throws IOException, MyException { + // 获取文件后缀名 + String ext = attach.getOriginalFilename().substring(attach.getOriginalFilename().lastIndexOf(".") + 1); + FastDFSFile file = new FastDFSFile(attach.getBytes(), ext); + NameValuePair[] meta_list = new NameValuePair[4]; + meta_list[0] = new NameValuePair("fileName", attach.getOriginalFilename()); + meta_list[1] = new NameValuePair("fileLength", String.valueOf(attach.getSize())); + meta_list[2] = new NameValuePair("fileExt", ext); + meta_list[3] = new NameValuePair("fileAuthor", "rkg"); + String filePath = FileManager.upload(file, meta_list); + // user.setFilePath(filePath); + // users.put(user.getUsername(), user); + return filePath; + } + + // public ResponseEntity download(@PathVariable String filePath, + // HttpServletResponse response) + @RequestMapping(value = "/download", method = RequestMethod.GET) + public ResponseEntity download(@RequestParam("filePath") String filePath, HttpServletResponse response) + throws IOException, MyException { + // User u = users.get(username); + // String filePath = u.getFilePath(); + // String filePath = ""; + String substr = filePath.substring(filePath.indexOf("group")); + String group = substr.split("/")[0]; + String remoteFileName = substr.substring(substr.indexOf("/") + 1); + // 重命名文件 + String specFileName = "rkg" + substr.substring(substr.indexOf(".")); + return FileManager.download(group, remoteFileName, specFileName); + } +} diff --git a/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java new file mode 100644 index 0000000..dccd905 --- /dev/null +++ b/src/main/java/com/nis/web/dao/impl/BaseRedisDao.java @@ -0,0 +1,13 @@ +package com.nis.web.dao.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +@Repository +public abstract class BaseRedisDao { + + @Autowired + protected RedisTemplate redisTemplate; + +} diff --git a/src/main/java/com/nis/web/service/fdfs/FastDFSFile.java b/src/main/java/com/nis/web/service/fdfs/FastDFSFile.java new file mode 100644 index 0000000..94bdcd4 --- /dev/null +++ b/src/main/java/com/nis/web/service/fdfs/FastDFSFile.java @@ -0,0 +1,80 @@ +package com.nis.web.service.fdfs; + +/** + *

Title: FastDFSFile.java

+ *

Description:

+ *

Company: IIE

+ * @author rkg + * @date 2018年5月16日 + * + */ + +public class FastDFSFile extends FileManagerConfig { + private static final long serialVersionUID = 1L; + + private byte[] content; + private String name; + private String ext; + private String length; + private String author = FILE_DEFAULT_AUTHOR; + + public FastDFSFile(byte[] content, String ext) { + this.content = content; + this.ext = ext; + } + + public FastDFSFile(byte[] content, String name, String ext) { + this.content = content; + this.name = name; + this.ext = ext; + } + + public FastDFSFile(byte[] content, String name, String ext, String length, String author) { + this.content = content; + this.name = name; + this.ext = ext; + this.length = length; + this.author = author; + } + + public byte[] getContent() { + return content; + } + + public void setContent(byte[] content) { + this.content = content; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getExt() { + return ext; + } + + public void setExt(String ext) { + this.ext = ext; + } + + public String getLength() { + return length; + } + + public void setLength(String length) { + this.length = length; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + +} diff --git a/src/main/java/com/nis/web/service/fdfs/FileManager.java b/src/main/java/com/nis/web/service/fdfs/FileManager.java new file mode 100644 index 0000000..8cafd28 --- /dev/null +++ b/src/main/java/com/nis/web/service/fdfs/FileManager.java @@ -0,0 +1,108 @@ +package com.nis.web.service.fdfs; + +import java.io.File; + +import org.csource.common.NameValuePair; +import org.csource.fastdfs.ClientGlobal; +import org.csource.fastdfs.StorageClient; +import org.csource.fastdfs.StorageServer; +import org.csource.fastdfs.TrackerClient; +import org.csource.fastdfs.TrackerServer; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +/** + *

Title: FileManager.java

+ *

Description:

+ *

Company: IIE

+ * @author rkg + * @date 2018年5月16日 + * + */ + +public class FileManager extends FileManagerConfig { + + private static final long serialVersionUID = 1L; + private static TrackerClient trackerClient; + private static TrackerServer trackerServer; + private static StorageServer storageServer; + private static StorageClient storageClient; + + static { + try { + String classPath = new File(FileManager.class.getResource("/").getFile()).getCanonicalPath(); + String fdfsClientConfigFilePath = classPath + File.separator + CLIENT_CONFIG_FILE; + ClientGlobal.init(fdfsClientConfigFilePath); + trackerClient = new TrackerClient(); + trackerServer = trackerClient.getConnection(); + storageClient = new StorageClient(trackerServer, storageServer); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 向fastdfs上传文件 + * @param file + * @param valuePairs + * @return + */ + public static String upload(FastDFSFile file, NameValuePair[] valuePairs) { + String[] uploadResults = null; + try { + // uploadResults = storageClient.upload_file(file.getContent(), file.getExt(), + // valuePairs); + uploadResults = storageClient.upload_file(file.getContent(), file.getExt(), valuePairs); + } catch (Exception e) { + e.printStackTrace(); + } + String groupName = uploadResults[0]; + String remoteFileName = uploadResults[1]; + + String fileAbsolutePath = PROTOCOL + TRACKER_NGNIX_ADDR + // + trackerServer.getInetSocketAddress().getHostName() + // + SEPARATOR + TRACKER_NGNIX_PORT + + SEPARATOR + groupName + SEPARATOR + remoteFileName; + return fileAbsolutePath; + } + + /** + * 从fastdfs下载文件 + * @param groupName + * @param remoteFileName + * @param specFileName + * @return + */ + public static ResponseEntity download(String groupName, String remoteFileName, String specFileName) { + byte[] content = null; + HttpHeaders headers = new HttpHeaders(); + try { + content = storageClient.download_file(groupName, remoteFileName); + headers.setContentDispositionFormData("attachment", + new String(specFileName.getBytes("UTF-8"), "iso-8859-1")); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return new ResponseEntity(content, headers, HttpStatus.CREATED); + } + + /** + * 根据组和文件名删除文件 + * @param group 文件所属组 + * @param filePath 文件存放路径,不包含group,例如文件url是http://10.0.6.192/group1/M00/00/01/CgAGwFr786aAegOQAADz3NN2rlY283.jpg,那么filePath=/M00/00/01/CgAGwFr786aAegOQAADz3NN2rlY283.jpg + * @return 返回0代表成功,其他则失败 + */ + public static Integer delete_file(String group, String filePath) { + Integer result = -1; + try { + result = storageClient.delete_file(group, filePath); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/src/main/java/com/nis/web/service/fdfs/FileManagerConfig.java b/src/main/java/com/nis/web/service/fdfs/FileManagerConfig.java new file mode 100644 index 0000000..942b1df --- /dev/null +++ b/src/main/java/com/nis/web/service/fdfs/FileManagerConfig.java @@ -0,0 +1,29 @@ +package com.nis.web.service.fdfs; + +import java.io.Serializable; + +/** + *

Title: FileManagerConfig.java

+ *

Description:

+ *

Company: IIE

+ * @author rkg + * @date 2018年5月16日 + * + */ + +public class FileManagerConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + public static final String FILE_DEFAULT_AUTHOR = "renkaige"; + + public static final String PROTOCOL = "http://"; + + public static final String SEPARATOR = "/"; + + public static final String TRACKER_NGNIX_ADDR = "10.0.6.192"; + + public static final String TRACKER_NGNIX_PORT = ""; + + public static final String CLIENT_CONFIG_FILE = "fdfs_client.conf"; +} diff --git a/src/main/java/com/nis/web/service/restful/TestRedisService.java b/src/main/java/com/nis/web/service/restful/TestRedisService.java new file mode 100644 index 0000000..cbc5b28 --- /dev/null +++ b/src/main/java/com/nis/web/service/restful/TestRedisService.java @@ -0,0 +1,14 @@ +package com.nis.web.service.restful; + +/** + * + *

Title: TestRedisService

+ *

Description: 测试redis事务

+ *

Company: IIE

+ * @author rkg + * @date 2018年5月17日 + * + */ +public interface TestRedisService { + public void saveConfigCompile(); +} diff --git a/src/main/java/com/nis/web/service/restful/TestRedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/TestRedisServiceimpl.java new file mode 100644 index 0000000..ccf221c --- /dev/null +++ b/src/main/java/com/nis/web/service/restful/TestRedisServiceimpl.java @@ -0,0 +1,36 @@ +package com.nis.web.service.restful; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.nis.datasource.DynamicJedisDataBase; +import com.nis.web.dao.impl.BaseRedisDao; + +@Service("testRedisServiceimpl") +public class TestRedisServiceimpl extends BaseRedisDao implements TestRedisService { + @Transactional + public void saveConfigCompile() { + DynamicJedisDataBase.setRedisDataBase(2, redisTemplate); + for (int i = 0; i < 10; i++) { + redisTemplate.boundZSetOps("1").add("a" + i, i); + if (i == 5) { + // int a = 1 / 0; + } + } + // 切换redis数据库 + DynamicJedisDataBase.setRedisDataBase(3, redisTemplate); + for (int i = 10; i < 20; i++) { + redisTemplate.boundZSetOps("1").add("a" + i, i); + if (i == 5) { + // int a = 1 / 0; + } + } + DynamicJedisDataBase.setRedisDataBase(4, redisTemplate); + for (int i = 20; i < 30; i++) { + redisTemplate.boundZSetOps("1").add("a" + i, i); + if (i == 25) { + int a = 1 / 0; + } + } + } +} diff --git a/src/main/resources/applicationContext-redis.xml b/src/main/resources/applicationContext-redis.xml new file mode 100644 index 0000000..80f8fe9 --- /dev/null +++ b/src/main/resources/applicationContext-redis.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fastdfs-client.properties b/src/main/resources/fastdfs-client.properties new file mode 100644 index 0000000..034e60e --- /dev/null +++ b/src/main/resources/fastdfs-client.properties @@ -0,0 +1,14 @@ +## fastdfs-client.properties + +fastdfs.connect_timeout_in_seconds = 5 +fastdfs.network_timeout_in_seconds = 30 + +fastdfs.charset = UTF-8 + +fastdfs.http_anti_steal_token = false +fastdfs.http_secret_key = FastDFS1234567890 +fastdfs.http_tracker_http_port = 80 + +#fastdfs.tracker_servers = 10.0.11.201:22122,10.0.11.202:22122,10.0.11.203:22122 +fastdfs.tracker_servers = 10.0.6.192:22122 + diff --git a/src/main/resources/fdfs_client.conf b/src/main/resources/fdfs_client.conf new file mode 100644 index 0000000..c3d1fe2 --- /dev/null +++ b/src/main/resources/fdfs_client.conf @@ -0,0 +1,10 @@ +connect_timeout = 2 +network_timeout = 30 +charset = UTF-8 +http.tracker_http_port = 8080 +http.anti_steal_token = no +http.secret_key = FastDFS1234567890 + +tracker_server = 10.0.6.192:22122 +#tracker_server = 10.0.11.248:22122 +#tracker_server = 10.0.11.249:22122 diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties index 1d60780..76b4524 100644 --- a/src/main/resources/jdbc.properties +++ b/src/main/resources/jdbc.properties @@ -84,9 +84,9 @@ jdbc.hiveA.url=jdbc:hive2://10.3.130.24:10000/default jdbc.hiveA.username=xa_z2_mesa jdbc.hiveA.key=aC/8fTC9vfPVhCk+CDzbAQ== #加密后密码 -#jdbc.hiveA.password=V3GyFlG8Mg01bTt8ykFVaA== +jdbc.hiveA.password=V3GyFlG8Mg01bTt8ykFVaA== #实际密码 -jdbc.hiveA.password=123!@#qwe +#jdbc.hiveA.password=123!@#qwe @@ -98,9 +98,9 @@ jdbc.hiveB.url=jdbc:hive2://10.3.130.25:10000/default jdbc.hiveB.username=xa_z2_mesa jdbc.hiveB.key=aC/8fTC9vfPVhCk+CDzbAQ== #加密后密码 -#jdbc.hiveB.password=V3GyFlG8Mg01bTt8ykFVaA== +jdbc.hiveB.password=V3GyFlG8Mg01bTt8ykFVaA== #实际密码 -jdbc.hiveB.password=123!@#qwe +#jdbc.hiveB.password=123!@#qwe bonecp.hive.idleMaxAgeInMinutes=60 @@ -123,4 +123,13 @@ jdbc.test.username=gk_pztest jdbc.test.key=cV9126WUYdojQjvuKNjidw== jdbc.test.password=OrTu/cLwlduYPW/tmxqNgQ== - +##################################################################################################################################### +##redis连接 +##################################################################################################################################### +redis.host=10.0.6.228 +redis.port=6379 +redis.pass= +redis.maxIdle=10 +redis.maxTotal=15 +redis.maxWaitMillis=1000 +redis.testOnBorrow=true diff --git a/src/main/resources/redis.properties b/src/main/resources/redis.properties new file mode 100644 index 0000000..9a6f198 --- /dev/null +++ b/src/main/resources/redis.properties @@ -0,0 +1,10 @@ +##################################################################################################################################### +##redis连接 +##################################################################################################################################### +redis.host=10.0.6.228 +redis.port=6379 +redis.pass= +redis.maxIdle=10 +redis.maxTotal=15 +redis.maxWaitMillis=1000 +redis.testOnBorrow=true diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml index f222c3d..cf6aa38 100644 --- a/src/main/resources/spring-mvc.xml +++ b/src/main/resources/spring-mvc.xml @@ -22,7 +22,6 @@ http://www.springframework.org/schema/cache/spring-cache.xsd"> - @@ -47,47 +46,53 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -95,6 +100,7 @@ + + + + + + + + + + @@ -185,7 +200,7 @@ - + @@ -215,11 +230,11 @@ - - - + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 5b58302..ec2ec0e 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -197,11 +197,11 @@ - - - com.nis.listener.SystemConfigListener - - + + + + + diff --git a/src/test/java/com/nis/test/RedisTest.java b/src/test/java/com/nis/test/RedisTest.java new file mode 100644 index 0000000..6a82a8e --- /dev/null +++ b/src/test/java/com/nis/test/RedisTest.java @@ -0,0 +1,31 @@ +package com.nis.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import com.nis.web.service.restful.TestRedisService; + +@WebAppConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +// @ContextConfiguration(locations = +// {"classpath:applicationContext-*.xml,classpath:spring-mvc.xml,classpath:mybatis-config.xml" +// }) +@ContextConfiguration(locations = { "classpath:applicationContext-redis.xml", "classpath:spring-mvc.xml" + // ,"classpath:mybatis-config.xml" +}) +public class RedisTest { + + @Autowired + TestRedisService configService; + + @Test + public void testTrans() { + configService.saveConfigCompile(); + } + +}