admin
2020-06-04 1d0da1ba12234afb77d604fec5da94d74f402b53
完善
6个文件已修改
3个文件已添加
246 ■■■■ 已修改文件
pom.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/BkzApplication.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/RedisConfig.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/SpringSecurityConfig.java 59 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/controller/ParseController.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/manager/RedisManager.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mybatis-config.xml 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/ks/tool/bkz/BkzApplicationTests.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -24,10 +24,12 @@
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
@@ -35,6 +37,16 @@
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
@@ -90,6 +102,11 @@
            <artifactId>aspectjrt</artifactId>
            <version>1.8.5</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.1.0</version>
        </dependency>
    </dependencies>
src/main/java/com/ks/tool/bkz/BkzApplication.java
@@ -1,13 +1,18 @@
package com.ks.tool.bkz;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = "com.ks.tool.bkz.dao")
public class BkzApplication {
    public static void main(String[] args) {
        SpringApplication.run(BkzApplication.class, args);
    }
}
src/main/java/com/ks/tool/bkz/RedisConfig.java
New file
@@ -0,0 +1,39 @@
package com.ks.tool.bkz;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@Configuration
public class RedisConfig {
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.timeout}")
    private int timeout;
    @Value("${spring.redis.jedis.pool.max-idle}")
    private int maxIdle;
    @Value("${spring.redis.jedis.pool.max-wait}")
    private long maxWaitMillis;
    @Value("${spring.redis.password}")
    private String password;
    @Bean
    public JedisPool redisPoolFactory() throws Exception {
        System.out.println("JedisPool注入成功!!");
        System.out.println("redis地址:" + host + ":" + port);
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMaxWait(maxWaitMillis);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
        return jedisPool;
    }
}
src/main/java/com/ks/tool/bkz/SpringSecurityConfig.java
@@ -1,37 +1,32 @@
package com.ks.tool.bkz;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//@Configuration
//@EnableWebSecurity
public class SpringSecurityConfig  extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
        http.authorizeRequests()
                .antMatchers("/").permitAll() //主路径允许访问
                .anyRequest().authenticated()  //验证
                .and()
                .logout().permitAll() //注销也是运行访问
                .and()
                .formLogin();
        http.csrf().disable();  //关闭csrf() 认证
    }
    @Override
    public void configure(WebSecurity web) throws Exception {
        super.configure(web);
        web.ignoring().antMatchers("/js/**", "/css/**", "/images/**");
    }
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        super.configure(auth);
    }
public class SpringSecurityConfig
//        extends WebSecurityConfigurerAdapter
{
//
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        super.configure(http);
//        http.authorizeRequests()
//                .antMatchers("/").permitAll() //主路径允许访问
//                .anyRequest().authenticated()  //验证
//                .and()
//                .logout().permitAll() //注销也是运行访问
//                .and()
//                .formLogin();
//        http.csrf().disable();  //关闭csrf() 认证
//    }
//
//    @Override
//    public void configure(WebSecurity web) throws Exception {
//        super.configure(web);
//        web.ignoring().antMatchers("/js/**", "/css/**", "/images/**");
//    }
//
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        super.configure(auth);
//    }
}
src/main/java/com/ks/tool/bkz/controller/ParseController.java
@@ -49,9 +49,10 @@
     * @return
     */
    @RequestMapping("uploadCookies")
    @ResponseBody
    public String uploadCookie(String cookies) {
        this.cookie = cookies;
        return "";
        return cookies;
    }
src/main/java/com/ks/tool/bkz/service/manager/RedisManager.java
New file
@@ -0,0 +1,43 @@
package com.ks.tool.bkz.service.manager;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import javax.annotation.Resource;
@Component
public class RedisManager {
    @Resource
    private JedisPool jedisPool;
    public void save(String key, String value, int expire) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.setex(key, expire, value);
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
    public void delete(String key) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.del(key);
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
    public String get(String key) {
        Jedis jedis = jedisPool.getResource();
        try {
            return jedis.get(key);
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
}
src/main/resources/application.yml
@@ -1,2 +1,47 @@
server:
  port: 8082
  port: 8082
spring:
  datasource:
    url: jdbc:mysql://gz-cdb-r13d0yi9.sql.tencentcdb.com:62929/test
    username: root
    password: Yeshi2016@
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      initial-size: 8
      min-idle: 1
      max-active: 20
      max-wait: 60000
      time-between-eviction-runsMillis: 60000
      min-evictable-idle-timeMillis: 300000
      validation-query: select 'x' FROM DUAL
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      pool-prepared-statements: true
      max-open-prepared-statements: 20
      max-pool-prepared-statement-per-connection-size: 20
      filters: stat
      connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
      use-global-data-source-stat: true
  data:
    mongodb:
      username: admin
      password: Yeshi2016@
      host: 193.112.35.168
      port: 27016
      database: flq
  redis:
    host: 127.0.0.1
    port: 6379
    password: 123456
    timeout: 5000
    jedis:
      pool:
        max-wait: 10000
        max-idle: 200
        max-active: 1024
mybatis:
  mapper-locations: classpath:mapper/*.xml
src/main/resources/mybatis-config.xml
New file
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!-- 配置全局属性 -->
    <settings>
        <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
        <setting name="useGeneratedKeys" value="true" />
        <!-- 使用列别名替换列名 默认:true -->
        <setting name="useColumnLabel" value="true" />
        <!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} -->
        <setting name="mapUnderscoreToCamelCase" value="true" />
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>
    <typeHandlers>
          <package name="com.yeshi.fanli.util.mybatishandler"/>
    </typeHandlers>
</configuration>
src/test/java/com/ks/tool/bkz/BkzApplicationTests.java
@@ -1,13 +1,21 @@
package com.ks.tool.bkz;
import com.ks.tool.bkz.service.manager.RedisManager;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
@SpringBootTest
class BkzApplicationTests {
    @Resource
    private RedisManager redisManager;
    @Test
    void contextLoads() {
        redisManager.save("test","123",10);
        System.out.println(redisManager.get("test"));
    }
}