基础架构fix
This commit is contained in:
@@ -21,6 +21,7 @@ import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.device.enums.DeviceType;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -31,6 +32,7 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Lazy
|
||||
public class XianGongAgvServiceImpl implements XianGongAgvService {
|
||||
private final DeviceAppService deviceAppService;
|
||||
private final ISysParamService paramService;
|
||||
|
||||
@@ -49,4 +49,16 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
|
||||
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
config.addAllowedOrigin("*");
|
||||
config.addAllowedHeader("*");
|
||||
config.addAllowedMethod("*");
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
package org.nl.config.saconfig;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 跨域过滤器
|
||||
* @author kong
|
||||
*/
|
||||
@Component
|
||||
@Order(-200)
|
||||
public class CorsFilter implements Filter {
|
||||
|
||||
static final String OPTIONS = "OPTIONS";
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
// 允许指定域访问跨域资源
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
// 允许所有请求方式
|
||||
response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
// 有效时间
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
// 允许的header参数
|
||||
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
// 如果是预检请求,直接返回
|
||||
if (OPTIONS.equals(request.getMethod())) {
|
||||
System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
|
||||
response.getWriter().print("");
|
||||
return;
|
||||
}
|
||||
|
||||
// System.out.println("*********************************过滤器被使用**************************");
|
||||
chain.doFilter(req, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
//package org.nl.config.saconfig;
|
||||
//
|
||||
//import org.springframework.core.annotation.Order;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.cors.CorsConfiguration;
|
||||
//
|
||||
//import javax.servlet.*;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.io.IOException;
|
||||
//
|
||||
///**
|
||||
// * 跨域过滤器
|
||||
// * @author kong
|
||||
// */
|
||||
//@Component
|
||||
//@Order(-200)
|
||||
//public class CorsFilter implements Filter {
|
||||
//
|
||||
// static final String OPTIONS = "OPTIONS";
|
||||
//
|
||||
// @Override
|
||||
// public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
// throws IOException, ServletException {
|
||||
// HttpServletRequest request = (HttpServletRequest) req;
|
||||
// HttpServletResponse response = (HttpServletResponse) res;
|
||||
// // 允许指定域访问跨域资源
|
||||
// response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
// // 允许所有请求方式
|
||||
// response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
// // 有效时间
|
||||
// response.setHeader("Access-Control-Max-Age", "3600");
|
||||
// // 允许的header参数
|
||||
// response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
// response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
//
|
||||
// // 如果是预检请求,直接返回
|
||||
// if (OPTIONS.equals(request.getMethod())) {
|
||||
// System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
|
||||
// response.getWriter().print("");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // System.out.println("*********************************过滤器被使用**************************");
|
||||
// chain.doFilter(req, res);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void init(FilterConfig filterConfig) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void destroy() {
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 622 B |
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* WebMvcConfigurer
|
||||
*
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-30
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
public class ConfigurerAdapter implements WebMvcConfigurer {
|
||||
/** 文件配置 */
|
||||
private final FileProperties properties;
|
||||
|
||||
public ConfigurerAdapter(FileProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
config.addAllowedOrigin("*");
|
||||
config.addAllowedHeader("*");
|
||||
config.addAllowedMethod("*");
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
FileProperties.ElPath path = properties.getPath();
|
||||
String avatarUtl = "file:" + path.getAvatar().replace("\\","/");
|
||||
String pathUtl = "file:" + path.getPath().replace("\\","/");
|
||||
registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,56 @@
|
||||
package org.nl.config.saconfig;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 跨域过滤器
|
||||
* @author kong
|
||||
*/
|
||||
@Component
|
||||
@Order(-200)
|
||||
public class CorsFilter implements Filter {
|
||||
|
||||
static final String OPTIONS = "OPTIONS";
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
// 允许指定域访问跨域资源
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
// 允许所有请求方式
|
||||
response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
// 有效时间
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
// 允许的header参数
|
||||
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
// 如果是预检请求,直接返回
|
||||
if (OPTIONS.equals(request.getMethod())) {
|
||||
System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
|
||||
response.getWriter().print("");
|
||||
return;
|
||||
}
|
||||
|
||||
// System.out.println("*********************************过滤器被使用**************************");
|
||||
chain.doFilter(req, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
//package org.nl.config.saconfig;
|
||||
//
|
||||
//import org.springframework.core.annotation.Order;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//import org.springframework.web.cors.CorsConfiguration;
|
||||
//
|
||||
//import javax.servlet.*;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.io.IOException;
|
||||
//
|
||||
///**
|
||||
// * 跨域过滤器
|
||||
// * @author kong
|
||||
// */
|
||||
//@Component
|
||||
//@Order(-200)
|
||||
//public class CorsFilter implements Filter {
|
||||
//
|
||||
// static final String OPTIONS = "OPTIONS";
|
||||
//
|
||||
// @Override
|
||||
// public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
// throws IOException, ServletException {
|
||||
// HttpServletRequest request = (HttpServletRequest) req;
|
||||
// HttpServletResponse response = (HttpServletResponse) res;
|
||||
// // 允许指定域访问跨域资源
|
||||
// response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
// // 允许所有请求方式
|
||||
// response.setHeader("Access-Control-Allow-Methods", "*");
|
||||
// // 有效时间
|
||||
// response.setHeader("Access-Control-Max-Age", "3600");
|
||||
// // 允许的header参数
|
||||
// response.setHeader("Access-Control-Allow-Headers", "*");
|
||||
// response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
//
|
||||
// // 如果是预检请求,直接返回
|
||||
// if (OPTIONS.equals(request.getMethod())) {
|
||||
// System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
|
||||
// response.getWriter().print("");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // System.out.println("*********************************过滤器被使用**************************");
|
||||
// chain.doFilter(req, res);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void init(FilterConfig filterConfig) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void destroy() {
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 622 B |
Reference in New Issue
Block a user