ctx webservice 整合 spring 简单实例

最近正好在做一个webservice的相关事情,这边就简单的介绍一下:

 

 

一.spring 托管的webservice 

1.web.xml配置文件内容
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
2.spring 配置内容
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

<jaxws:endpoint id="ApplySuperviseService" address="/ApplySuperviseService" implementor="cn.com.trueway.cc.ws.ApplySuperviseServiceImpl"/>
<jaxws:endpoint id="LmService" address="/LmService" implementor="cn.com.trueway.cc.ws.LmServiceImpl"/>

 

3.service
@WebService
public interface LmService {

@WebMethod
public String getSzmailFromLm(@WebParam(name="InfoXML")String InfoXML);

@WebMethod
public String feedBackToLm(@WebParam(name="InfoXML")String InfoXML);

@WebMethod
public String trunBackToLm(@WebParam(name="InfoXML")String InfoXML);

}

 

4.service 实现

@WebService(endpointInterface = "cn.com.trueway.cc.ws.LmService", serviceName = "LmService")
public class LmServiceImpl implements LmService {

 

 

详情:可以见如下链接:http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring和Netty都是非常流行的Java框架,它们可以很好地结合使用。Spring提供了依赖注入和面向切面编程等功能,而Netty则提供了高性能的网络通信能力。下面是Spring和Netty整合的步骤: 1. 引入Netty依赖 在pom.xml文件中添加以下依赖: ``` <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.25.Final</version> </dependency> ``` 2. 创建Netty服务器 创建一个Netty服务器,监听指定端口,接收客户端请求,并将请求转发给Spring容器处理。以下是一个简单的Netty服务器示例: ``` public class NettyServer { private int port; private ApplicationContext context; public NettyServer(int port, ApplicationContext context) { this.port = port; this.context = context; } public void start() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new ObjectEncoder()); pipeline.addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null))); pipeline.addLast(new NettyServerHandler(context)); } }) .option(ChannelOption.SO_BACKLOG, 128) .childOption(ChannelOption.SO_KEEPALIVE, true); ChannelFuture future = bootstrap.bind(port).sync(); future.channel().closeFuture().sync(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } } } ``` 3. 创建Netty服务器处理器 创建一个Netty服务器处理器,用于接收客户端请求并将请求转发给Spring容器处理。以下是一个简单的Netty服务器处理器示例: ``` public class NettyServerHandler extends ChannelInboundHandlerAdapter { private ApplicationContext context; public NettyServerHandler(ApplicationContext context) { this.context = context; } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Request) { Request request = (Request) msg; Object result = handleRequest(request); ctx.write(result); } } private Object handleRequest(Request request) { // 将请求转发给Spring容器处理 // ... } @Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace(); ctx.close(); } } ``` 4. 创建Spring容器 创建一个Spring容器,用于处理客户端请求。以下是一个简单Spring容器示例: ``` @Configuration @ComponentScan("com.example") public class AppConfig { @Bean public MyService myService() { return new MyServiceImpl(); } } ``` 5. 启动Netty服务器和Spring容器 在应用程序的入口处,启动Netty服务器和Spring容器。以下是一个简单的应用程序示例: ``` public class App { public static void main(String[] args) throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); NettyServer server = new NettyServer(8080, context); server.start(); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值