springboot配置webservice服务发布

简介: 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) {

}

}

相关文章
|
4天前
|
Java API 微服务
【Spring Boot系列】通过OpenAPI规范构建微服务服务接口
【4月更文挑战第5天】通过OpenAPI接口构建Spring Boot服务RestAPI接口
23 0
|
22天前
|
Java 调度 Spring
SpringBoot实现多线程定时任务动态定时任务配置文件配置定时任务
SpringBoot实现多线程定时任务动态定时任务配置文件配置定时任务
43 0
|
1月前
|
Java 数据处理
【十二】springboot整合WebService
【十二】springboot整合WebService
45 0
|
1月前
|
NoSQL Java Redis
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
245 1
|
1月前
|
SQL Java 数据库连接
springboot中配置mybatis别名该怎么写?
springboot中配置mybatis别名该怎么写?
28 0
|
4天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的医院核酸检测服务系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的医院核酸检测服务系统的详细设计和实现
31 0
|
11天前
|
Java Shell 测试技术
一次配置,多场景适用:Spring Boot多套配置文件的深度剖析
一次配置,多场景适用:Spring Boot多套配置文件的深度剖析
21 0
一次配置,多场景适用:Spring Boot多套配置文件的深度剖析
|
15天前
|
Java 容器
SpringBoot使用配置注解开启自动配置功能&整合spring-boot-configuration-processor
SpringBoot使用配置注解开启自动配置功能&整合spring-boot-configuration-processor
14 0
|
15天前
|
JSON 前端开发 安全
Springboot整合邮件服务
Springboot整合邮件服务
|
22天前
|
Java 应用服务中间件
Springboot启动的时候初始化的线程池默认配置tomcat
Springboot启动的时候初始化的线程池默认配置tomcat
13 1