@SpringBootApplication(scanBasePackages = {"com.spring.resource.cloud*"}) @ServletComponentScan({"com.spring.resource.cloud*"}) public class ResourceUploadGuestApplication { public static void main(String[] args) { SpringApplication.run(ResourceUploadGuestApplication.class, args); } @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ //创建FastJson信息转换对象 FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //创建Fastjosn对象并设定序列化规则 FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); // 中文乱码解决方案 List<MediaType> mediaTypes = new ArrayList<>(); mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);//设定json格式 fastJsonHttpMessageConverter.setSupportedMediaTypes(mediaTypes); //规则赋予转换对象 fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastJsonHttpMessageConverter); } }
使用上述启动入口,但是对应包下的servlet并没有注册成功
package com.spring.resource.cloud.servlet; @WebServlet(urlPatterns = "/resource/") @LoggerHeader(header = "操作日志servlet进行内容拦截") public class TakeLogServlet extends HttpServlet { Log log = LogFactory.getLog(TakeLogServlet.class); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Map<String, String[]> parameterMap = req.getParameterMap(); Set<Map.Entry<String, String[]>> entries = parameterMap.entrySet(); for (Map.Entry<String, String[]> entry:entries){ String key = entry.getKey(); String[] value = entry.getValue(); log.info(key+"="+ JSONObject.toJSONString(value)); resp.getWriter().print(JSONObject.toJSONString(value)); } } }