From b8caabab6c7b39745de6a213e50b3a0eaa6522c9 Mon Sep 17 00:00:00 2001 From: lenovo Date: Mon, 27 Aug 2018 10:27:10 +0800 Subject: [PATCH] 0827 10.25 redis lisi --- pom.xml | 193 ++++++++++++------ .../redis/SpringRedisConfiguration.java | 97 +++++++++ .../java/com/pro/info/entity/Standard.java | 4 +- .../service/impl/StandardServiceImpl.java | 15 +- .../pro/sys/controller/LoginController.java | 2 - .../sys/service/impl/ShiroServiceImpl.java | 5 +- src/main/resources/jdbc.properties | 13 -- src/main/resources/log4j.properties | 41 ---- src/main/resources/log4j2.xml | 16 ++ src/main/resources/redis.properties | 29 +++ src/main/resources/spring-mvc.xml | 14 +- src/main/resources/spring-root-mybatis.xml | 9 +- src/main/resources/spring-root-redis.xml | 36 ++++ src/main/web/WEB-INF/web.xml | 4 +- 14 files changed, 334 insertions(+), 144 deletions(-) create mode 100644 src/main/java/com/pro/config/redis/SpringRedisConfiguration.java delete mode 100644 src/main/resources/log4j.properties create mode 100644 src/main/resources/log4j2.xml create mode 100644 src/main/resources/redis.properties create mode 100644 src/main/resources/spring-root-redis.xml diff --git a/pom.xml b/pom.xml index 49bb4ca..4ad0ccb 100644 --- a/pom.xml +++ b/pom.xml @@ -16,124 +16,183 @@ - - junit - junit - 4.11 - test - - - org.springframework - spring-aop - 4.1.9.RELEASE - com.github.pagehelper pagehelper 3.7.5 + - org.springframework - spring-aspects - 4.1.9.RELEASE + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + org.springframework - spring-context - 4.1.9.RELEASE + spring-webmvc + 5.0.7.RELEASE + org.springframework - spring-core - 4.1.9.RELEASE + spring-jdbc + 5.0.7.RELEASE + org.springframework - spring-beans - 4.1.9.RELEASE + spring-tx + 5.0.7.RELEASE + + - org.springframework - spring-webmvc - 4.1.9.RELEASE + com.fasterxml.jackson.core + jackson-databind + 2.9.6 + + + - com.fasterxml.jackson.core - jackson-core - 2.8.0 + org.apache.taglibs + taglibs-standard-spec + 1.2.5 - com.fasterxml.jackson.core - jackson-databind - 2.8.0 + org.apache.taglibs + taglibs-standard-impl + 1.2.5 + - org.springframework - spring-expression - 4.1.9.RELEASE + mysql + mysql-connector-java + 5.1.46 + + + - com.alibaba - druid - 1.0.18 + org.mybatis + mybatis-spring + 1.3.2 + + - org.springframework - spring-jdbc - 4.1.9.RELEASE + org.aspectj + aspectjweaver + 1.9.1 + + - org.springframework - spring-tx - 4.1.9.RELEASE + com.alibaba + druid + 1.1.10 + + + + + org.mybatis mybatis - 3.3.0 + 3.4.6 + + + + - org.mybatis - mybatis-spring - 1.2.3 + org.apache.shiro + shiro-core + 1.4.0 + + - mysql - mysql-connector-java - 5.1.37 + org.apache.shiro + shiro-web + 1.4.0 + + - jstl - jstl - 1.2 + org.apache.shiro + shiro-spring + 1.4.0 + + + + + - log4j - log4j - 1.2.17 + org.springframework + spring-core + 5.0.7.RELEASE + + + org.springframework + spring-jcl + + - + + org.slf4j - slf4j-log4j12 - 1.7.13 + jcl-over-slf4j + 1.7.25 - + - org.apache.shiro - shiro-spring - 1.2.3 + org.slf4j + slf4j-api + 1.7.25 - org.apache.shiro - shiro-quartz - 1.2.3 + org.apache.logging.log4j + log4j-slf4j-impl + 2.11.0 + + + - javax.servlet - servlet-api - 2.5 + org.springframework.data + spring-data-redis + 2.0.9.RELEASE + + + + redis.clients + jedis + 2.9.0 + + + + + junit + junit + 4.12 + test + + + + \ No newline at end of file diff --git a/src/main/java/com/pro/config/redis/SpringRedisConfiguration.java b/src/main/java/com/pro/config/redis/SpringRedisConfiguration.java new file mode 100644 index 0000000..76442ea --- /dev/null +++ b/src/main/java/com/pro/config/redis/SpringRedisConfiguration.java @@ -0,0 +1,97 @@ +package com.pro.config.redis; + +import java.lang.reflect.Method; + +import javax.annotation.Resource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.CachingConfigurer; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; + +@Configuration @EnableCaching +public class SpringRedisConfiguration { + + private static Logger LOG=LoggerFactory.getLogger(SpringRedisConfiguration.class); + + @Bean @Resource + public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) { + + RedisCacheManager redisCacheManager = RedisCacheManager.create(connectionFactory); + LOG.info("Bean:对象redisCacheManager创建加载成功!"); + return redisCacheManager; + } + + @Bean + public KeyGenerator keyGenerator() { + + /* + * String : 内容不可改变的字符串 + * StringBuider: 内容可改变的字符容器,线程不安全,效率较高 + * StringBuffer: 内容可改变的字符容器,线程安全,效率较低 + * + * + */ + + KeyGenerator keyGenerator = new KeyGenerator() { + + @Override + public Object generate(Object target, Method method, Object... params) { + StringBuilder sb = new StringBuilder() + .append(target.getClass().getName()) + .append(".") + .append(method.getName()) + .append("("); + for (int i=0;i"+sb.toString()); + return sb.toString(); + } + + }; + + LOG.info("Bean:对象keyGenerator创建加载成功!"); + + return keyGenerator; + + } + + @Bean @Resource + public CachingConfigurer cachingConfigurer(CacheManager cacheManager,KeyGenerator keyGenerator) { + + CachingConfigurer redisCachingConfigurer = new CachingConfigurerSupport() { + + @Override + public CacheManager cacheManager() { + return cacheManager; + } + + @Override + public KeyGenerator keyGenerator() { + return keyGenerator; + } + + }; + + LOG.info("Bean:对象redisCachingConfigurer创建加载成功!"); + return redisCachingConfigurer; + + } + + +} diff --git a/src/main/java/com/pro/info/entity/Standard.java b/src/main/java/com/pro/info/entity/Standard.java index c5c4e0c..6cc1654 100644 --- a/src/main/java/com/pro/info/entity/Standard.java +++ b/src/main/java/com/pro/info/entity/Standard.java @@ -1,6 +1,8 @@ package com.pro.info.entity; -public class Standard { +import java.io.Serializable; + +public class Standard implements Serializable { private String standard_id; // private String standard_name; // diff --git a/src/main/java/com/pro/info/service/impl/StandardServiceImpl.java b/src/main/java/com/pro/info/service/impl/StandardServiceImpl.java index 546a79a..44fb479 100644 --- a/src/main/java/com/pro/info/service/impl/StandardServiceImpl.java +++ b/src/main/java/com/pro/info/service/impl/StandardServiceImpl.java @@ -7,10 +7,13 @@ import com.pro.info.mapper.StandardMapper; import com.pro.info.service.StandardService; import com.pro.sys.entity.Result; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import java.util.UUID; -@Service +@Service@CacheConfig(cacheNames = "standard") public class StandardServiceImpl implements StandardService { @Autowired @@ -22,7 +25,7 @@ public class StandardServiceImpl implements StandardService { * @param pageSize * @return */ - @Override + @Override@Cacheable public PageInfo getStandards(int page, int pageSize, Standard standardIn) { PageHelper.startPage(page,pageSize); return new PageInfo(standardMapper.getStandards(standardIn)); @@ -33,7 +36,7 @@ public class StandardServiceImpl implements StandardService { * @param standard * @return */ - @Override + @Override@CacheEvict(allEntries = true) public Result save(Standard standard) { if (standard.getStandard_id() != null && standard.getStandard_id() != ""){ if(standardMapper.update(standard) > 0){ @@ -54,7 +57,7 @@ public class StandardServiceImpl implements StandardService { * @param standard_ids * @return */ - @Override + @Override@CacheEvict(allEntries = true) public Result delete(String[] standard_ids) { if (standardMapper.delete(standard_ids) > 0){ return Result.successResult("信息被成功删除!"); @@ -67,7 +70,7 @@ public class StandardServiceImpl implements StandardService { * @param standard_id * @return */ - @Override + @Override@Cacheable public Standard getStandard(String standard_id) { return standardMapper.getStandard(standard_id); } @@ -78,7 +81,7 @@ public class StandardServiceImpl implements StandardService { * @param standard_status * @return */ - @Override + @Override@CacheEvict(allEntries = true) public Result updateStatus(String[] standard_ids, String standard_status) { if(standardMapper.updateStatus(standard_ids, standard_status) > 0){ return Result.successResult("状态被成功修改!"); diff --git a/src/main/java/com/pro/sys/controller/LoginController.java b/src/main/java/com/pro/sys/controller/LoginController.java index 6b19219..2eeebd5 100644 --- a/src/main/java/com/pro/sys/controller/LoginController.java +++ b/src/main/java/com/pro/sys/controller/LoginController.java @@ -26,7 +26,6 @@ public class LoginController { private ShiroService shiroService; @RequestMapping(value = "/login") public String Login(@RequestHeader(value="Via",required=false) String via , @RequestHeader("user-agent") String userAgent, String username, String password, String rememberMe, HttpSession session, Model model){ - System.out.println("name--"+username+"---pass---"+password); //判断是否为手机端访问 boolean is = Utils.isMobileDevice(via, userAgent); //主体,当前状态为没有认证的状态“未认证” @@ -58,7 +57,6 @@ public class LoginController { user = (User)subject.getPrincipal(); System.out.println("------->login:"+user); session.setAttribute("user",user); - System.out.println("++++++++++++++++++"+subject.getSession().getAttribute("user")); List menuList = shiroService.getMenuList(user); model.addAttribute("menuList",menuList); System.out.println("登录完成"); diff --git a/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java b/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java index effb5e9..c3bfdc7 100644 --- a/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java +++ b/src/main/java/com/pro/sys/service/impl/ShiroServiceImpl.java @@ -17,10 +17,8 @@ public class ShiroServiceImpl implements ShiroService { private ShiroMapper shiroMapper; public User getUserByUserName(String u_name) { - System.out.println("service----->username:" + u_name); //根据账号获取账号密码 User userInfo = shiroMapper.getUserByUserName(u_name); - System.out.println(userInfo); return userInfo; } @@ -46,7 +44,6 @@ public class ShiroServiceImpl implements ShiroService { List moduleList = shiroMapper.getMenuList(shiroMapper.getUserRoleByUserId(user.getU_id())); List mainMenuList = new ArrayList(); Menu currMainMenu=null; - System.out.println("-----.moduleList--"+moduleList); for(Module m : moduleList) { if(currMainMenu == null || !currMainMenu.getMenuId().equals(m.getM_pid())) { currMainMenu=new Menu(); @@ -62,7 +59,7 @@ public class ShiroServiceImpl implements ShiroService { currMainMenu.getSubMenuList().add(subMenu); } - System.out.println("----------////"+mainMenuList); + System.out.println("----------"+mainMenuList); return mainMenuList; } diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties index a35517f..dbf5c0d 100644 --- a/src/main/resources/jdbc.properties +++ b/src/main/resources/jdbc.properties @@ -2,44 +2,31 @@ url:jdbc:mysql://localhost:3306/prjdb?useUnicode=true&characterEncoding=utf8 driverClassName:com.mysql.jdbc.Driver username:root password:root - #------------------------------------------------------------------------------------------ #չ ͳfilters:stat ־filters:log4j sqlעfilters:wall filters:stat - #ӳ ʼӵĸ ȡʱĵȴʱ Сӳ maxIdleѾ maxActive:20 initialSize:1 maxWait:60000 minIdle:10 -maxIdle:15 - # 1.Destroy ̻߳ӵʱ 2.testWhileIdleж timeBetweenEvictionRunsMillis:60000 - #Destory߳⵽ǰӵԾʱ͵ǰʱIJֵminEvictableIdleTimeMillisرյǰ minEvictableIdleTimeMillis:300000 - #ǷsqlҪһѯ䡣mysqlͨΪSELECT 'X' validationQuery:SELECT 'x' - #ӵʱ⣬ʱtimeBetweenEvictionRunsMillisִvalidationQueryǷЧ testWhileIdle:true - #ʱִvalidationQueryǷЧ ûή testOnBorrow:false - #黹ʱִvalidationQueryǷЧ ûή testOnReturn:false - #ҪPSCacheô00ʱpoolPreparedStatementsԶ޸Ϊtrue maxOpenPreparedStatements:20 - #ڽӳremoveAbandonedTimeoutǿƹر removeAbandoned:true - #ָӽ೤ͱǿƹر removeAbandonedTimeout:1800 - #ָremoveabandonedʱǷ¼ǰ̵߳ĶջϢ־ logAbandoned:true \ No newline at end of file diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties deleted file mode 100644 index 8a989a5..0000000 --- a/src/main/resources/log4j.properties +++ /dev/null @@ -1,41 +0,0 @@ -### Log4j ### -### SpringҪweb.xmlָļλãӼ ### -#log4jĿĵأĿĵؿԶƣͺĶӦ -#[ level ] , appenderName1 , appenderName2 -log4j.rootLogger=debug, console - -#-----------------------------------# -#1 ־ĿĵΪ̨ -log4j.appender.console = org.apache.log4j.ConsoleAppender -log4j.appender.console.Target = System.out -log4j.appender.console.Threshold=DEBUG -####ָ־ʽһָĸʽ ### -#%c: ־ϢĿͨȫ -#%m: ָϢ,־Ϣ -#%n: һسзWindowsƽ̨Ϊ"/r/n"Unixƽ̨Ϊ"/n"־Ϣ -log4j.appender.console.layout = org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=[%c]-%m%n - -#-----------------------------------# -#2 ļСָߴʱһµļ -#log4j.appender.file = org.apache.log4j.RollingFileAppender -#־ļĿ¼ -#log4j.appender.file.File=log/tibet.log -#ļС -#log4j.appender.file.MaxFileSize=10mb -###־Ϣ### -#ͼ -#log4j.appender.file.Threshold=ERROR -#log4j.appender.file.layout=org.apache.log4j.PatternLayout -#log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n -#4 mybatis ʾSQL䲿 -log4j.logger.org.mybatis=DEBUG -#log4j.logger.cn.tibet.cas.dao=DEBUG -#log4j.logger.org.mybatis.common.jdbc.SimpleDataSource=DEBUG# -#log4j.logger.org.mybatis.common.jdbc.ScriptRunner=DEBUG# -#log4j.logger.org.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG# -#log4j.logger.java.sql.Connection=DEBUG -log4j.logger.java.sql=debug -log4j.logger.java.sql.Statement=debug -log4j.logger.java.sql.ResultSet=debug -log4j.logger.java.sql.PreparedStatement=debug diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..d6680b7 --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/redis.properties b/src/main/resources/redis.properties new file mode 100644 index 0000000..b29dd8d --- /dev/null +++ b/src/main/resources/redis.properties @@ -0,0 +1,29 @@ +#============================# +#==== Redis settings ====# +#============================# +#redis IP +redis.host=127.0.0.1 + +#redis ˿ +redis.port=6379 + +#redis +#redis.pass=redis#2017 + +#redis ֧16ݿ⣨൱ڲͬûʹͬӦóݱ˴˷ֿͬʱִ洢ͬʵ +redis.dbIndex=0 + +#redis ݹʱ䵥λ +redis.expiration=3000 + +#һ pool жٸ״̬Ϊ idle jedisʵ +redis.maxIdle=300 + +#һ pool ɷٸjedisʵ +redis.maxActive=600 + +#borrowһjedisʵʱĵȴʱ䣬ȴʱ䣬ֱ׳JedisConnectionException +redis.maxWait=1000 + +#borrowһjedisʵʱǷǰalidateΪtrueõjedisʵǿõģ +redis.testOnBorrow=true \ No newline at end of file diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml index ccace9b..78f9250 100644 --- a/src/main/resources/spring-mvc.xml +++ b/src/main/resources/spring-mvc.xml @@ -37,13 +37,13 @@ - - - - - - - + diff --git a/src/main/resources/spring-root-mybatis.xml b/src/main/resources/spring-root-mybatis.xml index 698bad2..5f7ba0f 100644 --- a/src/main/resources/spring-root-mybatis.xml +++ b/src/main/resources/spring-root-mybatis.xml @@ -20,7 +20,14 @@ - + + + + classpath:jdbc.properties + + classpath:redis.properties + + diff --git a/src/main/resources/spring-root-redis.xml b/src/main/resources/spring-root-redis.xml new file mode 100644 index 0000000..7c8f8c9 --- /dev/null +++ b/src/main/resources/spring-root-redis.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/web/WEB-INF/web.xml b/src/main/web/WEB-INF/web.xml index 0f21727..796f124 100644 --- a/src/main/web/WEB-INF/web.xml +++ b/src/main/web/WEB-INF/web.xml @@ -84,8 +84,8 @@ - + \ No newline at end of file -- Gitee