总结
谈到面试,其实说白了就是刷题刷题刷题,天天作死的刷。。。。。
为了准备这个“金三银四”的春招,狂刷一个月的题,狂补超多的漏洞知识,像这次美团面试问的算法、数据库、Redis、设计模式等这些题目都是我刷到过的
并且我也将自己刷的题全部整理成了PDF或者Word文档(含详细答案解析)
66个Java面试知识点
架构专题(MySQL,Java,Redis,线程,并发,设计模式,Nginx,Linux,框架,微服务等)+大厂面试题详解(百度,阿里,腾讯,华为,迅雷,网易,中兴,北京中软等)
算法刷题(PDF)
cxf-rt-transports-http
${project.version}
org.apache.cxf
cxf-rt-frontend-jaxws
${project.version}
可以看出,已经包含了 cxf 所需要的相关依赖了。
4.2 服务端接口定义
@WebService(name = “CommonService”, // 暴露服务名称
targetNamespace = “http://webservice.lli.com/”// 命名空间,一般是接口的包名倒序
)
public interface CommonService {
@WebMethod
String sayHello(@WebParam(name = “param”) String param);
@WebMethod
String getUser(@WebParam(name = “param”) String param);
}
创建一个接口,定义两个接口方法,分别用来返回不同的信息,实际中根据具体需求来定义接口方法以及参数。这里有几个注解解释一下:
@WebService
注解:表明该接口是个 WebService 服务,name 属性用来定义该 webservice 服务名称; targetNamespace 属性用来定义命名空间。
@WebMethod
注解:表明接口中的方法是用来提供具体的服务的。
4.3 服务端接口的实现
@WebService(serviceName = “CommonService”, // 与接口中指定的name一致
targetNamespace = “http://webservice.lli.com/”, // 与接口中的命名空间一致,一般是接口的包名倒
endpointInterface = “com.lli.webservice.CommonService”// 接口地址
)
@Component
public class CommonServiceImpl implements CommonService {
@Override
public String getUser(String param) {
User user = new User(“1”, “吹比龙”, “18”);
return user.toString();
}
}
其中 @WebService
注解中的 endpointInterface
属性用来定义服务的地址,这个地址和下面的 cxf 配置中要对应,下面再说明。
4.4 cxf 服务配置
@Configuration
public class CxfConfig {
@Autowired
private Bus bus;
@Autowired
CommonService commonService;
/** JAX-WS **/
@Bean
public Endpoint endpoint2() {
EndpointImpl endpoint = new EndpointImpl(bus, commonService);
endpoint.publish(“/CommonService”);
return endpoint;
}
}
这里的配置是将上面刚刚定义的 CommonService
接口发布到了 /services/CommonService
路径下,wsdl 文档路径为 http://localhost:9999/services/CommonService?wsdl
。
4.5 cxf client客户端
这里使用动态调用为例,代理的方式请看源码。
public class CxfClient {
public static void main(String[] args) throws Exception {
cl2();
}
/**
-
动态调用方式
-
@throws Exception
*/
public static void cl2() throws Exception {
// 创建动态客户端
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf
.createClient(“http://localhost:9999/services/CommonService?wsdl”);
// getUser 为接口中定义的方法名称 张三为传递的参数 返回一个Object数组
Object[] objects = client.invoke(“getUser”, “张三”);
System.out.println(objects[0]);
}
}
注意事项:如果在同一个工程中,上面的 localhost 需要修改成本机的 ip 地址,否则会创建 cxf client 失败。运行一下 client,如果控制台打印出如下信息表示 webservice 服务启动成功:
总结
在清楚了各个大厂的面试重点之后,就能很好的提高你刷题以及面试准备的效率,接下来小编也为大家准备了最新的互联网大厂资料。
中…(img-QfOPf8N7-1715008999145)]