zoukankan      html  css  js  c++  java
  • webservice的hello world

    整个项目的目录结构是

    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 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     4     <modelVersion>4.0.0</modelVersion>
     5     <parent>
     6         <groupId>org.springframework.boot</groupId>
     7         <artifactId>spring-boot-starter-parent</artifactId>
     8         <version>2.1.8.RELEASE</version>
     9         <relativePath/> <!-- lookup parent from repository -->
    10     </parent>
    11     <groupId>com.chenyun</groupId>
    12     <artifactId>webservice_test_v5</artifactId>
    13     <version>0.0.1-SNAPSHOT</version>
    14     <name>webservice_test_v5</name>
    15     <description>Demo project for Spring Boot</description>
    16 
    17     <properties>
    18         <java.version>1.8</java.version>
    19     </properties>
    20 
    21     <dependencies>
    22         <dependency>
    23             <groupId>org.springframework.boot</groupId>
    24             <artifactId>spring-boot-starter-web</artifactId>
    25         </dependency>
    26 
    27         <dependency>
    28             <groupId>org.springframework.boot</groupId>
    29             <artifactId>spring-boot-starter-test</artifactId>
    30             <scope>test</scope>
    31         </dependency>
    32 
    33         <dependency>
    34             <groupId>org.reficio</groupId>
    35             <artifactId>soap-builder</artifactId>
    36             <version>1.0.0-SNAPSHOT</version>
    37         </dependency>
    38     </dependencies>
    39 
    40     <repositories>
    41         <repository>
    42             <id>reficio</id>
    43             <url>http://repo.reficio.org/maven/</url>
    44         </repository>
    45     </repositories>
    46 
    47     <build>
    48         <plugins>
    49             <plugin>
    50                 <groupId>org.springframework.boot</groupId>
    51                 <artifactId>spring-boot-maven-plugin</artifactId>
    52             </plugin>
    53         </plugins>
    54     </build>
    55 </project>
  • 相关阅读:
    书单
    树莓派与 NATAPP 实现内网穿透
    WinForm分辨率适应-高DPI自动缩放
    ElasticSearch学习——搜索技术基础知识(上)
    JavaSE学习笔记-基础
    JavaSE学习笔记-第一个Java程序
    JavaSE学习笔记-Java开发环境搭建
    MySQL学习笔记-增删改查
    MySQL学习笔记-函数
    MySQL学习笔记-查询
  • 原文地址:https://www.cnblogs.com/chenyun-/p/11502446.html
Copyright © 2011-2022 走看看