webservice的hello world

整个项目的目录结构是

webservice的hello world_第1张图片

Mycontroller.java:可以在localhost:8080/hello中查看
 1 //Mycontroller.java
 2 
 3 package com.chenyun.controller;
 4 
 5 import org.springframework.web.bind.annotation.RequestMapping;
 6 import org.springframework.web.bind.annotation.RestController;
 7 
 8 @RestController
 9 public class Mycontroller {
10 
11     @RequestMapping("/hello")
12     public String sayname(){
13         return "hello";
14     }
15 }

WsImpl.java:

//WsImpl.java

package com.chenyun.impl;

import com.chenyun.service.Ws;

import javax.jws.WebService;

@WebService
public class WsImpl implements Ws {
    public String sayname(String name){
        return "name is" + name;
    }

    public String sayname2(String name){
        return "name is" + name;
    }
}

Ws.java

 1 //Ws.java
 2 
 3 package com.chenyun.service;
 4 
 5 import javax.jws.WebService;
 6 
 7 @WebService
 8 public interface Ws {
 9     String sayname(String name);
10     String sayname2(String name);
11 }
WebserviceServerFinalApplication.java
 1 //WebserviceServerFinalApplication.java
 2 
 3 package com.chenyun;
 4 
 5 import com.chenyun.impl.WsImpl;
 6 import org.springframework.boot.SpringApplication;
 7 import org.springframework.boot.autoconfigure.SpringBootApplication;
 8 
 9 import javax.xml.ws.Endpoint;
10 
11 @SpringBootApplication
12 public class WebserviceServerFinalApplication {
13     public static void main(String[] args) {
14         SpringApplication.run(WebserviceServerFinalApplication.class, args);
15         String url = "http://localhost:8081/Webservice";
16         Endpoint.publish(url,new WsImpl());
17         System.out.println("=====================================");
18         System.out.println("发布webservice成功");
19         System.out.println("=====================================");
20     }
21 }

pom.xml

 1 
 2  3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     4.0.0
 5     
 6         org.springframework.boot
 7         spring-boot-starter-parent
 8         2.1.8.RELEASE
 9          
10     
11     com.chenyun
12     webservice_test_v5
13     0.0.1-SNAPSHOT
14     webservice_test_v5
15     Demo project for Spring Boot
16 
17     
18         1.8
19     
20 
21     
22         
23             org.springframework.boot
24             spring-boot-starter-web
25         
26 
27         
28             org.springframework.boot
29             spring-boot-starter-test
30             test
31         
32 
33         
34             org.reficio
35             soap-builder
36             1.0.0-SNAPSHOT
37         
38     
39 
40     
41         
42             reficio
43             http://repo.reficio.org/maven/
44         
45     
46 
47     
48         
49             
50                 org.springframework.boot
51                 spring-boot-maven-plugin
52             
53         
54     
55 

 

转载于:https://www.cnblogs.com/chenyun-/p/11502446.html

你可能感兴趣的:(webservice的hello world)