总结
上述知识点,囊括了目前互联网企业的主流应用技术以及能让你成为“香饽饽”的高级架构知识,每个笔记里面几乎都带有实战内容。
很多人担心学了容易忘,这里教你一个方法,那就是重复学习。
打个比方,假如你正在学习 spring 注解,突然发现了一个注解@Aspect,不知道干什么用的,你可能会去查看源码或者通过博客学习,花了半小时终于弄懂了,下次又看到@Aspect 了,你有点郁闷了,上次好像在哪哪哪学习,你快速打开网页花了五分钟又学会了。
从半小时和五分钟的对比中可以发现多学一次就离真正掌握知识又近了一步。
人的本性就是容易遗忘,只有不断加深印象、重复学习才能真正掌握,所以很多书我都是推荐大家多看几遍。哪有那么多天才,他只是比你多看了几遍书。
import org.apache.axis2.rpc.client.RPCServiceClient;
public class WebServiceClient {
public static void main(String[] args) throws Exception {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(“http://192.168.0.105:8080/Axis2Demo_war_exploded/services/HelloService”);
options.setTo(targetEPR);
Object[] entryArgs = new Object[]{4, 2};
QName qName = new QName(“http://ws.apache.org/axis2”, “add”);
Object result = serviceClient.invokeBlocking(qName, entryArgs, new Class[]{int.class})[0];
qName = new QName(“http://ws.apache.org/axis2”, “send”);
serviceClient.invokeRobust(qName, new Object[]{“hello world!”});
}
}
Soap UI
Apache CXF
==========
Apache CXF是一个开源的、全功能的,容易使用的Web服务框架。CXF是两个项目的结合:由IONA技术公司开发的Celtix和由Codehaus主持的团队开发的XFire。
CXF支持的特性非常广泛,但特性主要在以下一些方面:
-
支持的Web服务标准包括: SOAP WS-Addressing WS-Policy WS-ReliableMessaging WS-Security WS-SecurityPolicy WS-SecureConversation
-
JAS-WS API,用于Web服务开发 WSDL优先支持工具 Java优先支持
-
JAX-RS(JSR 311 1.0)API,用于RESTful Web服务开发
-
…
⬆️内容摘自Wiki百科。
发布服务
====
使用 Maven 构建项目,POM文件内容如下:
<?xml version="1.0" encoding="UTF-8"?><project xmlns=“http://maven.apache.org/POM/4.0.0”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
4.0.0
org.example
CXFDemo
1.0-SNAPSHOT
org.apache.cxf
cxf-rt-frontend-jaxws
3.4.0
org.apache.cxf
cxf-rt-transports-http
3.4.0
org.apache.cxf
cxf-rt-transports-http-jetty
3.4.0
org.apache.cxf
cxf-rt-transports-http-jetty
3.4.0
编写一个服务接口,定义 sayHi 方法:
package org.example.services;
import javax.jws.WebService;
// 声明这是一个Ws服务接口
@WebService
public interface HelloWorld {
// 定义服务方法
String sayHi(String name);
}
编写一个服务接口的实现类:
package org.example.services;
import javax.jws.WebService;
@WebService(endpointInterface = “org.example.services.HelloWorld”, serviceName = “HelloWorld”)
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String name) {
return "hi, " + name;
}
}
再编写一个发布服务的主类 Main :
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.example.services.HelloWorld;
import org.example.services.HelloWorldImpl;
public class Main {
public static void main(String[] args) {
HelloWorldImpl implementor = new HelloWorldImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(HelloWorld.class);
svrFactory.setAddress(“http://localhost:9000/helloworld”);
svrFactory.setServiceBean(implementor);
svrFactory.create();
}
}
运行后即可访问
http://localhost:9000/helloworld?wsdl 查看该服务,从WSDL的描述文件中也能看出 HelloWorld 服务提供了 sayHi 方法,且该方法需要一个字符串参数,返回值也为字符串。
使用 SoapUI 调用该方法示例:
通过代码也可以实现客户端调用 Web Service :
import org.example.services.HelloWorld;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
public class WsClient {
private static final QName SERVICE_NAME = new QName(“http://services.example.org/”, “HelloWorld”);
private static final QName PORT_NAME = new QName(“http://services.example.org/”, “HelloWorldPort”);
public static void main(String[] args) {
Service service = Service.create(SERVICE_NAME);
String endpointAddress = “http://localhost:9000/helloworld”;
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
HelloWorld helloWorld = service.getPort(HelloWorld.class);
System.out.println(helloWorld.sayHi(“SearchNull”));
}
}
Spring整合CXF
===========
在Spring框架中可以集合 Apache CXF 框架发布 Web Service 服务,通过 Maven 或其他方式将CXF所需的Jar包导入项目中,编写 Web Service 接口及实现类即可。
package org.example.webservices;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
-
@WebService注解标记一个webservice接口
-
@param targetNamespace 指定命名空间,默认使用包名的反转.
-
@param serviceName 对外发布的服务名称
-
@param portName wsdl:portName,默认为服务名 + Port
*/
@WebService(
targetNamespace = “http://services.example.org/”,
serviceName = “HelloService”,
portName = “HelloServicePort”
)
public interface IHelloService {
/**
-
@WebResult注解指定从返回值至WSDL或XML元素的映射,将此注解应用于客户端或服务端接口(SEI)方法之上。
-
@param name 当返回值列示在 WSDL 文件中并且在连接上的消息中找到该返回值时,指定该返回值的名称。对于 RPC 绑定,这是用于表示返回值的
-
@param targetNamespace 指定返回值的 XML 命名空间。仅当操作类型为 RPC 或者操作是文档类型并且参数类型为 BARE 时才使用此参数。(字符串)
-
@WebMethod注解表示作为 Web Service 的方法,将此注解应用于服务端接口(SEI)的方法上。
-
@param operationName 指定与此方法相匹配的 wsdl:operation 的名称,默认值为Java方法的名称
-
@WebParam注解用于指定方法参数即Web Service方法的消息部件和XML元素的映射
-
@param name 参数的名称,如果操作是RPC(远程过程调用)类型并且未指定portName属性,则表示参数的wsdl:port属性的名称
*/
@WebResult(name = “helloRequest”, targetNamespace = “http://services.example.org/”)
@WebMethod(operationName=“sayHello”)
public String hello(@WebParam(name = “msg”)String name);
}
xxxxxxxxxxbr package org.example.webservices;brbrimport javax.jws.WebMethod;brimport javax.jws.WebParam;brimport javax.jws.WebResult;brimport javax.jws.WebService;brbr/**br * @WebService注解标记一个webservice接口br br * @param targetNamespace 指定命名空间,默认使用包名的反转.br * @param serviceName 对外发布的服务名称br * @param portName wsdl:portName,默认为服务名 + Portbr/brbr@WebService(br targetNamespace = “http://services.example.org/”,br serviceName = “HelloService”,br portName = "HelloServicePort"br)brpublic interface IHelloService {br /**br * @WebResult注解指定从返回值至WSDL或XML元素的映射,将此注解应用于客户端或服务端接口(SEI)方法之上。br *br * @param name 当返回值列示在 WSDL 文件中并且在连接上的消息中找到该返回值时,指定该返回值的名称。对于 RPC 绑定,这是用于表示返回值的br * @param targetNamespace 指定返回值的 XML 命名空间。仅当操作类型为 RPC 或者操作是文档类型并且参数类型为 BARE 时才使用此参数。(字符串)br *br * @WebMethod注解表示作为 Web Service 的方法,将此注解应用于服务端接口(SEI)的方法上。br *br * @param operationName 指定与此方法相匹配的 wsdl:operation 的名称,默认值为Java方法的名称br *br * @WebParam注解用于指定方法参数即Web Service方法的消息部件和XML元素的映射br * @param name 参数的名称,如果操作是RPC(远程过程调用)类型并且未指定portName属性,则表示参数的wsdl:port属性的名称br */br @WebResult(name = “helloRequest”, targetNamespace = “http://services.example.org/”)br @WebMethod(operationName=“sayHello”)br public String hello(@WebParam(name = “msg”)String name);br}br
Web Service 接口的实现类
package org.example.webservices.impl;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import org.springframework.stereotype.Service;
import org.exmaple.webservices.IHelloService;
@WebService(
endpointInterface = “org.example.services.IHelloService”
)
@SOAPBinding(style=Style.RPC)
public class IHelloServiceImpl implements IHelloService {
@Override
public String hello(String name) {
return "Hello, " + name;
}
}
xxxxxxxxxxbr package org.example.webservices.impl;brbrimport javax.jws.WebService;brimport javax.jws.soap.SOAPBinding;brimport javax.jws.soap.SOAPBinding.Style;brbrimport org.springframework.stereotype.Service;brimport org.exmaple.webservices.IHelloService;brbr@WebService(br endpointInterface = "org.example.services.IHelloService"br)br@SOAPBinding(style=Style.RPC)brpublic class IHelloServiceImpl implements IHelloService {br @Overridebr public String hello(String name) {br return "Hello, " + name;br }br}br
实现 Web Service 的服务端后则需要对Spring项目整合CXF的一些配置,在 web.xml 中配置CXF框架路由。
cxf
Ending
Tip:由于文章篇幅有限制,下面还有20个关于MySQL的问题,我都复盘整理成一份pdf文档了,后面的内容我就把剩下的问题的目录展示给大家看一下
如果觉得有帮助不妨【转发+点赞+关注】支持我,后续会为大家带来更多的技术类文章以及学习类文章!(阿里对MySQL底层实现以及索引实现问的很多)
吃透后这份pdf,你同样可以跟面试官侃侃而谈MySQL。其实像阿里p7岗位的需求也没那么难(但也不简单),扎实的Java基础+无短板知识面+对某几个开源技术有深度学习+阅读过源码+算法刷题,这一套下来p7岗差不多没什么问题,还是希望大家都能拿到高薪offer吧。
盘整理成一份pdf文档了,后面的内容我就把剩下的问题的目录展示给大家看一下**
如果觉得有帮助不妨【转发+点赞+关注】支持我,后续会为大家带来更多的技术类文章以及学习类文章!(阿里对MySQL底层实现以及索引实现问的很多)
[外链图片转存中…(img-L9G2iLvA-1715074070275)]
[外链图片转存中…(img-NZD0y6LI-1715074070276)]
吃透后这份pdf,你同样可以跟面试官侃侃而谈MySQL。其实像阿里p7岗位的需求也没那么难(但也不简单),扎实的Java基础+无短板知识面+对某几个开源技术有深度学习+阅读过源码+算法刷题,这一套下来p7岗差不多没什么问题,还是希望大家都能拿到高薪offer吧。