• springboot配置webservice服务发布


    1、自动配置类:

    @Configuration
    public class AutoConfiguration {
    @Bean
        public ServletRegistrationBean registrationAxisServlet(AxisServlet axisServlet) {
            ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(axisServlet, "/services/*");
            // servletRegistrationBean.setLoadOnStartup(100);//默认为-1访问时才初始化
            return servletRegistrationBean;
        }
    
        @SuppressWarnings("rawtypes")
        @Bean
        public ServletListenerRegistrationBean listenerRegistrationAxisServlet() {
            return new ServletListenerRegistrationBean<ConfigAxisServletContextListener>(new ConfigAxisServletContextListener());
        }
    
        @Bean
        public AxisServlet axisServlet() {
            return new AxisServlet();
        }
    }

    2、配置路径:

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class ConfigAxisServletContextListener implements ServletContextListener {
    
        private final Logger logger = LoggerFactory.getLogger(getClass());
    
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            
            logger.info("测试信息,进入处理server-config.wsdd的JAVA类");
    
            String wsdd = "server-config.wsdd"; 
    
            File target = new File(sce.getServletContext().getRealPath("/WEB-INF") + File.separator + wsdd);
            logger.info("server-config.wsdd 的路径为:",target.getAbsolutePath());
            if (!target.exists()) {
                try {
                    target.getParentFile().mkdirs();
                    target.createNewFile();
                } catch (IOException e) {
                    logger.debug("获取创建【/WEB-INF】路径出错:" + e.getMessage(), e);
                }
    
                String path = "/config/" + wsdd;
                File source = new File(path);
    
                try (InputStream is = new FileInputStream(source); FileOutputStream os = new FileOutputStream(target);) {
                    int bytesRead = 0;
                    byte[] buffer = new byte[10 * 1024];
                    while ((bytesRead = is.read(buffer, 0, buffer.length)) != -1) {
                        os.write(buffer, 0, bytesRead);
                    }
                } catch (IOException e) {
                    logger.warn("将文件【config/" + wsdd + "】复制到【/WEB-INF】下出错:" + e.getMessage());
                }
            }
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
    
        }
    
    }
  • 相关阅读:
    洛谷P1421 小玉买文具
    洛谷P1035 级数求和
    洛谷 P2337 【[SCOI2012]喵星人的入侵】
    洛谷P1002 过河卒
    洛谷 P4073 [WC2013]平面图
    洛谷 P4705 玩游戏
    python3.7-初学篇-06
    python3.7-初学篇-04
    python3.7-初学篇-03
    python3.7-初学篇-02
  • 原文地址:https://www.cnblogs.com/liangblog/p/13181037.html
Copyright © 2020-2023  润新知