SSM+Redis+Shiro+Solr+Vue.js整合项目

手摸手教你优雅的实现电商项目中的Solr搜索功能,整合SSM框架和Shiro安全框架;教你用Vue.JS和ElementUI写出超漂亮的页面

技术栈

  • 后端: SSM + Shiro + Redis + Solr

  • 前端: Vue.JS + ElementUI

测试环境

IDEA + Maven + Tomcat8

项目设计

ssm-redis-solr
├── README
├── README.md
├── db
│   ├── sys_schema.sql  -- 建表SQL
│   └── tb_item.sql  -- 商品数据,共934条数据
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── cn
│   │   │       └── tycoding
│   │   │           ├── controller  -- SpringMVC的控制层(web层)
│   │   │           ├── credentials  -- shiro密码加密验证服务类CredentialsMatcher,用于登录错误次数限制
│   │   │           ├── entity  -- javaBean实体类
│   │   │           ├── mapper  -- mybatis-mapper层接口和XML映射文件
│   │   │           ├── realm -- shiro自定义Realm实现类
│   │   │           ├── service -- service服务层接口
│   │   │           └── utils -- 通用util工具类
│   │   ├── resources
│   │   │   ├── mybatis -- mybatis配置文件
│   │   │   ├── other -- 存放参数的配置文件
│   │   │   └── spring -- spring集成shiro,myabtis,mvc,redis,solr的配置文件
│   │   └── webapp
│   │       ├── WEB-INF
│   │       ├── goods.html  -- 商品列表页
│   │       ├── index.html  -- 项目首页
│   │       ├── login.html  -- 登录页
│   │       └── static -- 前端静态依赖文件
│   └── test

 

写在前面

  1. 本项目中使用的8081端口。
  2. 你需要在本地或服务器上配置Solr和Redis,文档中都配置在本地演示的。其中:redis占用6379端口(默认)、solr配置在Tomcat中,你可以下载我在GitHub上发布的配置好的solr,solr占用8080端口。
  3. 使用命令redis-server &命令启动Redis,启动成功会显示一个大Logo。
  4. 启动部署了solr的Tomcat,默认使用8080端口,启动成功后用浏览器访问http://localhost:8080/solr/index.html,如果进入了solr的管理页面证明Solr配置、启动成功。
  5. 本例中将solr和redis部署在本地电脑上,如果你仔细阅读了这篇文档,启动项目应该是很容易的。如果你把solr或redis部署在其他地方,请自行修改resource/spring/spring-solr.xmlresource/other/redis-config.properties配置文件信息。
  6. 请修改resource/other/jdbc.properties中连接数据库的信息。
  7. 只有完成了上述步骤后再启动项目,不然项目会因为连接不上solr或redis而报错。

准备

Shiro

关于Shiro,我这里写了详细的SSM框架整合Shiro安全框架的文档,利用SSM框架+Shiro框架实现用户-角色-权限管理系统;

Solr & Spring-Data-Solr

Solr需要单独部署到Tomcat服务器上,我这里提供自己已经安装和配置好的Tomcat和Solr: Github

注意事项:

  1. 部署Solr的Tomcat端口和本地项目的端口不能相同,会冲突。

  2. 注意Github仓库solr-tomcat/webapps/solr/WEB-INF/web.xml中solrhome的位置要修改为自己的。

起步

启动Solr和Redis

如果访问localhost:8080/solr/index.html出现Solr Admin页则启动成功。

初始化表结构

CREATE DATABASE ssm_redis DEFAULT CHARACTER SET utf8;

具体的数据库约束文件和表数据请看:ssm-redis-solr/db

这里我们模拟添加了934条商品数据

搭建SSM-Shiro集成环境

搭建SSM-Redis集成环境

集成SSM-Redis开发环境,首先你需要安装Redis并启动Redis-Server,然后就是在项目中搭建Spring-Data-Redis的运行环境:

创建redis-config.properties配置文件

redis.host=127.0.0.1
redis.port=6379
redis.pass=
redis.database=0
redis.maxIdle=300
redis.maxWait=3000
redis.testOnBorrow=true

创建spring-redis.xml

<?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"
       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">

    <context:property-placeholder location="classpath:other/*.properties"/>
    <!-- redis 相关配置 -->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <!-- 最大空闲数 -->
        <property name="maxIdle" value="${redis.maxIdle}"/>
        <!-- 连接时最大的等待时间(毫秒) -->
        <property name="maxWaitMillis" value="${redis.maxWait}"/>
        <!-- 在提取一个jedis实例时,是否提前进行验证操作;如果为true,则得到的jedis实例均是可用的 -->
        <property name="testOnBorrow" value="${redis.testOnBorrow}"/>
    </bean>
    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="${redis.host}"/>
        <property name="port" value="${redis.port}"/>
        <property name="password" value="${redis.pass}"/>
        <property name="poolConfig" ref="poolConfig"/>
    </bean>

    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="jedisConnectionFactory"/>
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值