创建springboot入门小案例

开发环境

IDEA:IntelliJ IDEA 2019.1.3 x64
springboot版本:2.2.0
jdk版本:jdk1.8.0_202
maven版本:3.6.1

创建springboot入门小案例

1、点击 “Create New Project”
在这里插入图片描述
2、点击 “Spring Initializr”,再点击 “Next”
在这里插入图片描述
3、填写完 “Project Metadata” 后,点击 “Next”
在这里插入图片描述
4、点击 “Web”,再勾选 “Spring Web”,再点击 “Next”
在这里插入图片描述
5、此处可以修改 “项目名称”“项目路径”,最后点击 “Finish”
在这里插入图片描述
6、点击 “OK”
在这里插入图片描述
7、自动构建的springboot项目结构如下
在这里插入图片描述
8、创建一个controller,测试springboot项目

package com.jeff.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Jeff
 * @description TODO
 * @date 2019/10/24
 */

@RestController
public class HelloWordController {

    @RequestMapping("hello")
    public String hello() {

        return "HelloWord";
    }

}

9、启动springboot项目,打开浏览器访问 http://localhost:8080/hello
在这里插入图片描述

源码地址:

https://gitee.com/jiefu813/jf-springboot

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个使用Spring Boot搭建WebService的简单入门案例: 1.创建Spring Boot项目,在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> ``` 2.创建一个WebService类,在其中定义需要暴露的方法: ```java @WebService public interface HelloWorldService { @WebMethod String sayHello(String name); } ``` ```java @WebService(endpointInterface = "com.example.demo.webservice.HelloWorldService") public class HelloWorldServiceImpl implements HelloWorldService { @Override public String sayHello(String name) { return "Hello " + name + "!"; } } ``` 3.配置WebService的端点和实现类: ```java @Configuration public class WebServiceConfig { @Bean public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet() { MessageDispatcherServlet servlet = new MessageDispatcherServlet(); servlet.setApplicationContext(new AnnotationConfigApplicationContext(WebServiceConfig.class)); servlet.setTransformWsdlLocations(true); return new ServletRegistrationBean<>(servlet, "/ws/*"); } @Bean(name = "helloWorld") public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema xsdSchema) { DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); wsdl11Definition.setPortTypeName("HelloWorldPort"); wsdl11Definition.setLocationUri("/ws"); wsdl11Definition.setTargetNamespace("http://www.example.com/demo/webservice"); wsdl11Definition.setSchema(xsdSchema); return wsdl11Definition; } @Bean public XsdSchema xsdSchema() { return new SimpleXsdSchema(new ClassPathResource("hello.xsd")); } } ``` 4.创建XSD文件定义WebService的参数和返回值: ```xml <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/demo/webservice" xmlns:tns="http://www.example.com/demo/webservice" elementFormDefault="qualified"> <xs:element name="sayHelloRequest"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="sayHelloResponse"> <xs:complexType> <xs:sequence> <xs:element name="result" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> ``` 5.启动应用程序,访问http://localhost:8080/ws/helloWorld.wsdl,将会看到生成的WSDL文件。 6.使用SOAPUI等工具测试webservice。 以上就是一个简单的Spring Boot Webservice入门案例
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值