springboot 打war 采坑

第一坑 2018-09-26 15:44:22.908 INFO 4700 --- [on(3)-127.0.0.1] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@440c79a5: startup date [Wed Sep 26 15:44:08 CST 2018]; root of context hierarchy 2018-09-26 15:44:22.912 INFO 4700 --- [on(3)-127.0.0.1] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483647 2018-09-26 15:44:22.943 INFO 4700 --- [on(3)-127.0.0.1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown 2018-09-26 15:44:22.946 INFO 4700 --- [on(3)-127.0.0.1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans 2018-09-26 15:44:22.962 INFO 4700 --- [on(3)-127.0.0.1] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed 26-Sep-2018 15:44:24.114 警告 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [ROOT] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 26-Sep-2018 15:44:24.115 警告 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [ROOT] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 26-Sep-2018 15:44:24.116 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4b6150a]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@1d4f0f7c]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. [2018-09-26 03:44:24,133] Artifact xdd:war: Error during artifact deployment. See server log for details. 26-Sep-2018 15:44:25.420 信息 [Abandoned connection cleanup thread] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access. java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access. at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311) at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:986) at com.mysql.jdbc.AbandonedConnectionCleanupThread.checkContextClassLoaders(AbandonedConnectionCleanupThread.java:90) at com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:63) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) 原因 @Resource注解导致的问题 监听器中不要使用 @Resource注解 使用@Autowired注解即可 问题查找方式 打成war包放到tomcat下运行 然后去查询tomcat目录下的日志 查找原因

springboot 导出文件

@ResponseBody @RequestMapping("/export") public byte[] exportPhone(HttpServletResponse response) throws UnsupportedEncodingException { StringBuffer buff = new StringBuffer(); List<User> users = userService.findAll(); for (int i = 0; i < users.size(); i++) { buff.append(users.get(i).toString()); buff.append("\r\n"); } String fileName = "用户" + StringUtil.dateFormat("yyyy年MM月dd日HH时mm分ss秒", new Date()) + ".txt"; fileName = URLEncoder.encode(fileName, "UTF-8"); response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment;filename=" + fileName); return buff.toString().getBytes(); }

SpringBoot 多数据源

##springboot 2.x Mybatis 多数据源 先照着配,仔细看文档,文档最后有细节说明 application.yml 细节 数据库信息需要在 hikari 节点下 参数名称 jdbc-url 与 driver-class-name server: port: 8080 spring: datasource: hikari: test1: driver-class-name: com.mysql.cj.jdbc.Driver jdbc-url: jdbc:mysql://127.0.0.1:3306/db2?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC username: root password: ****** test2: driver-class-name: com.mysql.cj.jdbc.Driver jdbc-url: jdbc:mysql://127.0.0.1:3306/db2?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC username: root password: ****** 配置文件 两个配置文件基本一致,名称不同 一个有@Primary 注解一个没有 DataSource1Config package com.sykj.jdj.config.datasource; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import javax.sql.DataSource; @Configuration @MapperScan(basePackages = "com.sykj.jdj.dao.test1", sqlSessionFactoryRef = "test1SqlSessionFactory") //配置需要扫描的包 public class DataSource1Config { @Bean(name = "test1") @Qualifier("test1") @Primary @ConfigurationProperties(prefix = "spring.datasource.hikari.test1") public DataSource test1DataSource() { DataSource build = DataSourceBuilder.create().build(); return build; } @Bean(name = "test1SqlSessionFactory") // 表示这个数据源是默认数据源 @Primary // @Qualifier表示查找Spring容器中名字为test1DataSource的对象 public SqlSessionFactory test1SqlSessionFactory(@Qualifier("test1") DataSource datasource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(datasource); //配置扫描的xml Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath:mapper/test1/*.xml"); bean.setMapperLocations(resources); return bean.getObject(); } @Bean("test1SqlSessionTemplate") // 表示这个数据源是默认数据源 @Primary public SqlSessionTemplate test1SqlSessionTemplate( @Qualifier("test1SqlSessionFactory") SqlSessionFactory sessionfactory) { return new SqlSessionTemplate(sessionfactory); } } ###DataSource2Config ...

springboot 和 vue-resource 跨域访问

vue-resource 配置 import VueResource from 'vue-resource' Vue.use(VueResource); Vue.http.options.root = 'http://127.0.0.1:10030'; Vue.http.options.emulateJSON = true; springboot(2.x版本) 配置 这个注解放到单独的接口上则表示这个接口支持跨域 接口放到Controller上 则表示这个Controller种的所有接口支持跨域 接口放到父类Controller上则表示继承的该父类的所有Controller支持跨域 @CrossOrigin 使用这个注解 使用 vue-resource methods: { getcode() { this.$http.post('user/register/getPhoneVerificationCode', {'phone': this.phone}).then(function (res) { console.log("验证码获取成功"); console.log(res); }, function (res) { console.log(res); console.log("验证码获取失败") }); }, register() { console.log(this.phone) console.log(this.password) } } springboot @ResponseBody @RequestMapping("/pageQuery") public Result pageQuery(@NotNull @Min(1) Integer page, @NotNull @Max(300) Integer limit) { return userService.pagedQueryUser(page, limit); }

springboot 统一参数校验配置

采坑 1号坑: 参数长度校验时特殊字符经过url编码时 1位变3位长度校验会出现问题 思路 通过全局异常处理器 来拦截参数校验的异常 进行统一的参数校验处理 步骤 导入jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> 验证配置 package com.***.config; import org.hibernate.validator.HibernateValidator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; /** * 全局验证配置 * * @author imsjw * @Date Created in 15:42 2018/6/7 */ @Configuration public class ValidatorConfig { @Bean public MethodValidationPostProcessor methodValidationPostProcessor() { MethodValidationPostProcessor postProcessor = new MethodValidationPostProcessor(); /**设置validator模式为快速失败返回*/ postProcessor.setValidator(validator()); return postProcessor; } @Bean public Validator validator() { ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class) .configure() .addProperty("hibernate.validator.fail_fast", "true") .buildValidatorFactory(); Validator validator = validatorFactory.getValidator(); return validator; } } 全局异常处理 ...

SpringBoot配置分离

SpringBoot配置分离 首先有三个配置文件 application.yml application-dev.yml application-prod.yml 通用配置写在[application.yml]文件中 每个环境独有的配置写在[application-xxx.yml]文件中 1.设置默认的配置文件 在[application.yml]中指定默认配置 spring: profiles: active: dev-local 2.项目启动时添加参数,指定配置文件 命令行启动时添加参数[spring.profiles.active],如果不添加参数则走默认配置 jar包启动命令 java -jar ***.jar --spring.profiles.active=prod 创建时间 2019年08月22 更新时间 2022年3月1日

thymeleaf 语法

标签中字符串拼接 th:onclick='${"goRead("+menu.***+")"}' 头部引用 引用部分 <head th:replace="template/head :: head(~{::title})"> <title>添加</title> </head> 被引用部分 <!DOCTYPE html> <html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"> <head th:fragment="head(title)"> <title th:replace="${title}">标题</title> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/> <link rel="shortcut icon" type="image/x-icon" th:href="@{/img/logo.ico}" media="screen"/> <link rel="stylesheet" th:href="@{/css/layui.css}"/> <script src="http://cdn.*****.com/js/jquery/jquery-3.3.1.min.js"></script> </head> </html> 循环 方式1 <select name="fatherId"> <option value="">根</option> <option th:each="item : ${menus}" th:value="${item.id}" th:text="${item.name}"></option> </select> 方式2 <th:block th:each="item:${roles}"> <input type="checkbox" lay-skin="primary" name="roles" th:value="${item.id}" th:title="${item.name}"> </th:block> 引用 <footer th:replace="文件路径::fragment值"></footer> 示例 引用 <footer th:replace="footer::footer"></footer> 被引用的 <div xmlns:th="http://www.thymeleaf.org" th:fragment="footer" class="layui-footer"> </div> js中使用 ...

Tortoise 码云 ssh使用

一.先在码云创建一个项目不做介绍 二.生成ssh公钥和私钥 开始菜单搜索PuTTYgen并打开 点击Generate开始生成 然后鼠标在上方的空白区域随便乱晃,直到生成好为止 保存私钥,点击下方的Save private key 将私钥保存到任意一个位置这个文件等下要用到 保存公钥,将上方方框中的公钥全部复制下来到一个文本文件中,等下会用到 三.在码云设置上公钥 点击个人图标选择设置,进入个人设置界面 点击左侧安全设置下的 “SSH公钥” 复制公钥到码云,并设置公钥标题,标题随便填一下吧 我写的是 “SSH” 将第二部生成的公钥复制到码云中 四.设置本地Git 选择一个文件夹作为项目文件夹 在项目文件夹上右击选择 “在这里创建版本库”,然后点击确认即可 在文件夹中右击选择TortoiseGit->设置 设置远端 选择Git下的远端选项 分别填入如下类容 远端: 随便起一个名字,我这边是和项目名相同 Url 项目的ssh (码云中进入项目 选择克隆下载中的ssh地址) 推送URl: 和上方的Url相同即可 putty秘钥: 选择第二步操作中的私钥 最好点击下方的添加保存即可 五.推送项目 右击Git提交,选择需要推送的文件 选择提交并推送 点击提交并推送之后会弹出一个新窗口 请勾选 “已知变更” 因为是首次提交,不勾选可能会出现错误,以后推送的时候就不需要勾选这个选项了 点击确定,即可推送完成

unity 问题

使用unity打包成ios项目时 如果unity项目中使用了反射基本上就会有问题 ios这边不支持反射 所以一些常用的C#的反射库还是不要使用了 如果一定要使用某些反射的库 一定要仔细查询一下这个库是否支持ios

VS 生成之后自动复制文件

在对应的项目上右击属性->生成事件->生成后事件 命令行中添加以下命令,则自动复制头文件到对应的项目目录下,这样就无需通过手动去复制头文件的方式引用静态库 xcopy ".\*.h" "..\RegCenter" /s /h /d /y