首页新闻找找看学习计划

SpringBoot注册servlet未生效

0
悬赏园豆:5 [待解决问题]
@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));
        }


    }
}
白壮丽的主页 白壮丽 | 初学一级 | 园豆:197
提问于:2018-03-23 16:22
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册