13 changed files with 355 additions and 94 deletions
@ -0,0 +1,17 @@ |
|||||
|
package io.xtfs.jwebfs.annotation; |
||||
|
|
||||
|
|
||||
|
import java.lang.annotation.ElementType; |
||||
|
import java.lang.annotation.Retention; |
||||
|
import java.lang.annotation.RetentionPolicy; |
||||
|
import java.lang.annotation.Target; |
||||
|
|
||||
|
/** |
||||
|
* 免toKEN验证注解 |
||||
|
* 注解不仅被保存到class文件中,jvm加载class文件之后,仍然存在 |
||||
|
*/ |
||||
|
@Target({ElementType.METHOD,ElementType.TYPE}) |
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
public @interface PassToken { |
||||
|
boolean required() default true; |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
package io.xtfs.jwebfs.configure; |
||||
|
|
||||
|
import org.apache.commons.logging.Log; |
||||
|
import org.apache.commons.logging.LogFactory; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.web.servlet.MultipartConfigFactory; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.core.env.Environment; |
||||
|
|
||||
|
import javax.servlet.MultipartConfigElement; |
||||
|
import java.io.File; |
||||
|
|
||||
|
@Configuration |
||||
|
public class EnvConfig { |
||||
|
private Log log = LogFactory.getLog(EnvConfig.class); |
||||
|
|
||||
|
@Autowired |
||||
|
private Environment env; |
||||
|
|
||||
|
/** |
||||
|
* 获取大数据链接信息 |
||||
|
* 项目初始化的时候完成操作 |
||||
|
* @return |
||||
|
*/ |
||||
|
@Bean |
||||
|
public static String yxDbConf(){ |
||||
|
//读取当前运行位置
|
||||
|
String curPath=System.getProperty("user.dir"); |
||||
|
return curPath; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 文件上传临时路径 |
||||
|
* @return |
||||
|
*/ |
||||
|
@Bean |
||||
|
public MultipartConfigElement multipartConfigElement(){ |
||||
|
MultipartConfigFactory factory = new MultipartConfigFactory(); |
||||
|
String tempUrl = System.getProperty("user.dir") + File.separator + "upload" + File.separator + "tmp"; |
||||
|
System.out.println("临时目录:" + tempUrl); |
||||
|
File file = new File(tempUrl); |
||||
|
if (!file.exists()) { |
||||
|
file.mkdirs(); |
||||
|
} |
||||
|
factory.setLocation(tempUrl); |
||||
|
return factory.createMultipartConfig(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
package io.xtfs.jwebfs.configure; |
||||
|
|
||||
|
import io.xtfs.jwebfs.interceptor.ChInterceptor; |
||||
|
import org.apache.commons.logging.Log; |
||||
|
import org.apache.commons.logging.LogFactory; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.format.FormatterRegistry; |
||||
|
import org.springframework.format.datetime.DateFormatter; |
||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
|
||||
|
|
||||
|
|
||||
|
@Configuration |
||||
|
public class YcWebMvcConfigurer implements WebMvcConfigurer { |
||||
|
//日志初始化
|
||||
|
private static Log log = LogFactory.getLog(YcWebMvcConfigurer.class); |
||||
|
|
||||
|
/** |
||||
|
* 注册拦截器 拦截 store 开头的uri |
||||
|
* @param registry |
||||
|
*/ |
||||
|
@Override |
||||
|
public void addInterceptors(InterceptorRegistry registry) { |
||||
|
registry.addInterceptor(new ChInterceptor()).addPathPatterns("/store/**") |
||||
|
.addPathPatterns("/admin/**") |
||||
|
.excludePathPatterns("/agent/**") |
||||
|
.excludePathPatterns("/upload/**") |
||||
|
.excludePathPatterns("**/passport/login") |
||||
|
.excludePathPatterns("**/passport/logout"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 前后分离的系统,进行跨域配置 |
||||
|
* @param registry |
||||
|
*/ |
||||
|
@Override |
||||
|
public void addCorsMappings(CorsRegistry registry){ |
||||
|
registry.addMapping("/**") |
||||
|
.allowedOriginPatterns("*") |
||||
|
.allowedMethods("GET","POST"); |
||||
|
// .allowedHeaders("*");
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 日期格式化 |
||||
|
* @param registry |
||||
|
*/ |
||||
|
@Override |
||||
|
public void addFormatters(FormatterRegistry registry){ |
||||
|
registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss")); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package io.xtfs.jwebfs.exception; |
||||
|
|
||||
|
/** |
||||
|
* 全局异常 |
||||
|
*/ |
||||
|
public class ChException extends RuntimeException { |
||||
|
private String msg; |
||||
|
private int code; |
||||
|
|
||||
|
public String getMsg() { |
||||
|
return msg; |
||||
|
} |
||||
|
|
||||
|
public void setMsg(String msg) { |
||||
|
this.msg = msg; |
||||
|
} |
||||
|
|
||||
|
public int getCode() { |
||||
|
return code; |
||||
|
} |
||||
|
|
||||
|
public void setCode(int code) { |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public ChException(String msg, int code) { |
||||
|
this.msg = msg; |
||||
|
this.code = code; |
||||
|
} |
||||
|
|
||||
|
public ChException(String msg) { |
||||
|
this.msg = msg; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
package io.xtfs.jwebfs.interceptor; |
||||
|
|
||||
|
|
||||
|
import org.apache.commons.lang.StringUtils; |
||||
|
import org.apache.commons.logging.Log; |
||||
|
import org.apache.commons.logging.LogFactory; |
||||
|
import org.springframework.http.HttpMethod; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.web.method.HandlerMethod; |
||||
|
import org.springframework.web.servlet.HandlerInterceptor; |
||||
|
import org.springframework.web.servlet.ModelAndView; |
||||
|
import io.xtfs.jwebfs.annotation.PassToken; |
||||
|
import io.xtfs.jwebfs.exception.ChException; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.lang.reflect.Method; |
||||
|
|
||||
|
@Component |
||||
|
public class ChInterceptor implements HandlerInterceptor { |
||||
|
private static Log log = LogFactory.getLog(ChInterceptor.class); |
||||
|
|
||||
|
@Override |
||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
||||
|
String uri = request.getRequestURI(); |
||||
|
// 判断是否是数据库监控的
|
||||
|
if(uri.contains("/druid/**") || uri.contains("/api/**")){ |
||||
|
return true; |
||||
|
} |
||||
|
// options 放过
|
||||
|
if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) { |
||||
|
return true; |
||||
|
} |
||||
|
// 从请求头中获取token
|
||||
|
String token = request.getHeader("access-token"); |
||||
|
// 如果不是映射到方法直接通过
|
||||
|
if(!(handler instanceof HandlerMethod)){ |
||||
|
return true; |
||||
|
} |
||||
|
HandlerMethod handlerMethod = (HandlerMethod) handler; |
||||
|
Method method = handlerMethod.getMethod(); |
||||
|
//检查是否有passtoken注释,有则跳过认证
|
||||
|
if (method.isAnnotationPresent(PassToken.class)) { |
||||
|
PassToken passToken = method.getAnnotation(PassToken.class); |
||||
|
if (passToken.required()) { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
//默认全部检查
|
||||
|
else { |
||||
|
// 执行认证
|
||||
|
if (token==null || StringUtils.isBlank(token)) { |
||||
|
throw new ChException("token为空,token为必须参数"); |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置输出头,添加跨域 |
||||
|
* @param response |
||||
|
*/ |
||||
|
private void setHeader(HttpServletResponse response,HttpServletRequest request){ |
||||
|
//跨域的header设置
|
||||
|
response.setHeader("Access-control-Allow-Origin", request.getHeader("Origin")); |
||||
|
response.setHeader("Access-Control-Allow-Methods", request.getMethod()); |
||||
|
response.setHeader("Access-Control-Allow-Credentials", "true"); |
||||
|
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers")); |
||||
|
// 个性化主机设置
|
||||
|
response.setHeader("chhong","true"); |
||||
|
// 防止乱码
|
||||
|
response.setHeader("Content-Type","application/json;charset=UTF-8"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
||||
|
// 拦截post
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
||||
|
// 完成后的请求
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
<?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> |
||||
|
<setting name="cacheEnabled" value="true" /> <!-- 全局映射器启用缓存 --> |
||||
|
<setting name="useGeneratedKeys" value="true" /> <!-- 允许 JDBC 支持自动生成主键 --> |
||||
|
<setting name="defaultExecutorType" value="REUSE" /> <!-- 配置默认的执行器 --> |
||||
|
<!-- <setting name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl" /> <!– 指定 MyBatis 所用日志的具体实现 –>--> |
||||
|
<setting name="logImpl" value="SLF4J" /> <!-- 指定 MyBatis 所用日志的具体实现 --> |
||||
|
<setting name="mapUnderscoreToCamelCase" value="true"/> <!--驼峰式命名 --> |
||||
|
</settings> |
||||
|
</configuration> |
||||
@ -1,22 +0,0 @@ |
|||||
package io.xtfs.jwebfs.repository; |
|
||||
|
|
||||
import io.xtfs.jwebfs.bean.WbFile; |
|
||||
import org.springframework.data.domain.Page; |
|
||||
import org.springframework.data.domain.Pageable; |
|
||||
import org.springframework.data.jpa.repository.JpaRepository; |
|
||||
|
|
||||
public interface WbFileRepository extends JpaRepository<WbFile,Integer> { |
|
||||
/** |
|
||||
* single |
|
||||
* @param id |
|
||||
* @return |
|
||||
*/ |
|
||||
WbFile findAllById(Integer id); |
|
||||
|
|
||||
/** |
|
||||
* list |
|
||||
* @param pageable |
|
||||
* @return |
|
||||
*/ |
|
||||
Page<WbFile> findAll(Pageable pageable); |
|
||||
} |
|
||||
@ -1,44 +1,33 @@ |
|||||
# 应用服务 WEB 访问端口 |
# 服务器信息 |
||||
server.port=8099 |
server.port=9091 |
||||
|
|
||||
# |
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver |
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/wbfs |
|
||||
spring.datasource.username=root |
|
||||
spring.datasource.password=root |
|
||||
# |
|
||||
#Java代码实体字段命名与数据库表结构字段之间的名称映射策略 |
|
||||
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl |
|
||||
#下面配置开启后,会禁止将驼峰转为下划线 |
|
||||
#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl |
|
||||
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect |
|
||||
# 调试语句 |
|
||||
spring.jpa.show-sql=true |
|
||||
# |
|
||||
# logback日志操作 |
# logback日志操作 |
||||
logging.config=classpath:logback-spring.xml |
logging.config=classpath:logback-spring.xml |
||||
logging.path=./logs/ |
logging.path=./logs/ |
||||
|
|
||||
|
server.servlet.context-path=/ |
||||
|
mybatis.mapper-locations=classpath*:/mapper/ycmall/*.xml |
||||
|
# 开启调试sql语句 |
||||
|
logging.level.yc.mall.api.mapper=DEBUG |
||||
|
# 临时文件存放 |
||||
|
#location.tempDir=/upload/temp |
||||
|
|
||||
|
# 格式化全局时间字段 |
||||
|
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss |
||||
|
# 指定时间区域类型 |
||||
|
spring.jackson.time-zone=GMT+8 |
||||
|
|
||||
# |
# |
||||
#spring.datasource.hikari.connection-timeout=1200 |
spring.servlet.multipart.enabled=true |
||||
#spring.datasource.hikari.connection-test-query=SELECT * FROM DUAL; |
# 设置自定义的临时文件夹路径 |
||||
|
spring.servlet.multipart.location=./upload/tmp |
||||
## Spring HikariConfig |
|
||||
# 事务自动提交 - 默认值:true |
#文件大小 |
||||
spring.datasource.hikari.auto-commit=true |
server.tomcat.max-http-form-post-size=2MB |
||||
# 连接测试查询 - Using the JDBC4 <code>Connection.isValid()</code> method to test connection validity can be more efficient on some databases and is recommended. |
|
||||
# 如果你的驱动程序支持JDBC4,强烈建议不要设置此属性。 |
# 静态资源 |
||||
spring.datasource.hikari.connection-test-query=select 1 |
spring.mvc.static-path-pattern=/upload/** |
||||
# 连接超时时间 - 默认值:30秒。 |
|
||||
spring.datasource.hikari.connection-timeout=30000 |
# 设置日志级别为DEBUG模式 |
||||
# 连接池中允许闲置的最长时间 - 默认值:10分钟 |
#log4j.rootLogger=DEBUG, stdout |
||||
spring.datasource.hikari.idle-timeout=600000 |
|
||||
# 一个连接生命时长(毫秒),超时而没被使用则被释放 - 默认值:30分钟 |
|
||||
spring.datasource.hikari.max-lifetime=1800000 |
|
||||
# 连接池中允许的最大连接数,包括闲置和使用中的连接 - 默认值:10 |
|
||||
spring.datasource.hikari.maximum-pool-size=100 |
|
||||
# 连接池中允许的最小空闲连接数 - 默认值:10。 |
|
||||
spring.datasource.hikari.minimum-idle=10 |
|
||||
# 连接被测试活动的最长时间 - 默认值:5秒。 |
|
||||
spring.datasource.hikari.validation-timeout=5000 |
|
||||
# 指定连接池的名称 - 默认自动生成 |
|
||||
spring.datasource.hikari.pool-name=HikaraPool-1 |
|
||||
|
|||||
@ -0,0 +1,15 @@ |
|||||
|
<?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> |
||||
|
<setting name="cacheEnabled" value="true" /> <!-- 全局映射器启用缓存 --> |
||||
|
<setting name="useGeneratedKeys" value="true" /> <!-- 允许 JDBC 支持自动生成主键 --> |
||||
|
<setting name="defaultExecutorType" value="REUSE" /> <!-- 配置默认的执行器 --> |
||||
|
<!-- <setting name="logImpl" value="org.apache.ibatis.logging.stdout.StdOutImpl" /> <!– 指定 MyBatis 所用日志的具体实现 –>--> |
||||
|
<setting name="logImpl" value="SLF4J" /> <!-- 指定 MyBatis 所用日志的具体实现 --> |
||||
|
<!-- <setting name="logImpl" value="LOG4J" /> <!– 指定 MyBatis 所用日志的具体实现 –>--> |
||||
|
<setting name="mapUnderscoreToCamelCase" value="true"/> <!--驼峰式命名 --> |
||||
|
</settings> |
||||
|
</configuration> |
||||
@ -0,0 +1,26 @@ |
|||||
|
# |
||||
|
#============================================================================ |
||||
|
# Configure Main Scheduler Properties |
||||
|
#============================================================================ |
||||
|
org.quartz.scheduler.instanceName:ChjyjScheduler |
||||
|
org.quartz.scheduler.instanceId=AUTO |
||||
|
org.quartz.scheduler.rmi.export:false |
||||
|
org.quartz.scheduler.rmi.proxy:false |
||||
|
org.quartz.scheduler.wrapJobExecutionInUserTransaction:false |
||||
|
org.quartz.threadPool.class:org.quartz.simpl.SimpleThreadPool |
||||
|
org.quartz.threadPool.threadCount=10 |
||||
|
org.quartz.threadPool.threadPriority:5 |
||||
|
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread:true |
||||
|
org.quartz.jobStore.misfireThreshold:60000 |
||||
|
#============================================================================ |
||||
|
# Configure JobStore |
||||
|
#============================================================================ |
||||
|
# 存储方式使用JobStoreTX,也就是数据库 |
||||
|
org.quartz.jobStore.class:org.quartz.impl.jdbcjobstore.JobStoreTX |
||||
|
org.quartz.jobStore.driverDelegateClass:org.quartz.impl.jdbcjobstore.StdJDBCDelegate |
||||
|
org.quartz.jobStore.useProperties:true |
||||
|
#数据库中quartz表的表名前缀 |
||||
|
org.quartz.jobStore.tablePrefix:qrtz_ |
||||
|
org.quartz.jobStore.dataSource:qzDS |
||||
|
# 是否使用集群 |
||||
|
org.quartz.jobStore.isClustered=false |
||||
Loading…
Reference in new issue