当前位置:首页 > Web开发 > 正文

说闲但确实很少有时间能静下心来写点东西

2024-03-31 Web开发

比来一段时间,说忙也不是很忙,说闲但确实很少有时间能静下心来写点对象。但于我而言,做任何典礼感很重要,就算没时间对峙,那典礼感也不能丢,这是一种态度,也是最后的底线。今天的这篇推文,是很久以前就实践过了,前几天又整理了一下,上周没有发,本周必需要更新,不敢再犯错了,终究已经2020年了。好了开始正题吧。

1、依赖环境 <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-features-logging</artifactId> <version>${cxf.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.11.1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.11.1</version> <scope>test</scope> </dependency>

注意: 上面的写法是maven加载包的方法,如果不想创建maven项目,可以直接把cxf/lib下的所有包加载到你的项目中也是可以的

2、根基写法 @WebService() @SOAPBinding(style = SOAPBinding.Style.RPC) public interface MyService { /** * 人员根基信息盘问校验 * * @param name * @return String * @throws GeneralException */ @WebMethod String sayHello(@WebParam(name = "name") String name); }

注意:如果action不清楚的话,建议不写

实现类: public class MyserviceImpl implements Myservice { @Override public String sayHello(String name) { return name + ",Hello!"; }

注意:

实现类必需和接口在同一级目录下,否则会呈现参数无法被识另外情况

3、颁布方法

(1).默认的颁布方法

我颁布就是用的这种方法,将颁布的代码写在监听器里,这种方法最简单

public class StartListener implements ServletContextListener { private Logger log = LogManager.getLogger(StartListener.class); private final Myservice myservice = new MyserviceImpl(); private Endpoint endpoint = null; String address=":7001/myservice"; @Override public void contextInitialized(ServletContextEvent servletContextEvent) { endpoint = Endpoint.publish(address, myservice); log.info("颁布MyserviceImpl webservice告成,地点:" + address); } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { if (this.endpoint.isPublished()) this.endpoint.stop(); log.error("处事被销毁……"); } }

(2)spring颁布

1)引入Spring包

插手如下依赖

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency>

或者直接引入二进制包

spring-aop-5.1.4.RELEASE.jar spring-beans-5.1.4.RELEASE.jar spring-context-5.1.4.RELEASE.jar spring-core-5.1.4.RELEASE.jar spring-expression-5.1.4.RELEASE.jar spring-web-5.1.4.RELEASE.jar

2)在classPath下添加applicationContext-cxf.xml配置文件

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="" xmlns:amq="" xmlns:xsi="" xmlns:jaxws="" xmlns:soap="" xsi:schemaLocation=" http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/schemas/jaxws.xsd"> <!-- 这里配置的是webservice的实现类, --> <!--相当于:JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); --> <jaxws:server address="/" serviceClass="lss.medicare.ydjy.ejb.YDJYHospServiceBean"> <!-- 配置动静拦截器 --> <!-- 这种方法已颠末期 --> <!-- <jaxws:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean> </jaxws:inInterceptors> <jaxws:outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean> </jaxws:outInterceptors> --> <!-- 这个是替代类 --> <jaxws:features> <bean class="org.apache.cxf.ext.logging.LoggingFeature"/> </jaxws:features> </jaxws:server> </beans>

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31443.html