spring boot 集成cxf 获取wsdl文件报错_从零开始学SpringBoot,从入门到熟练,从简介到集成...

本文介绍了Spring Boot的核心功能,包括快速集成、开发、启动和部署,以及内嵌Servlet容器、starter简化依赖配置、自动装配bean和零配置特性。通过搭建Spring Boot应用和测试,展示了其易用性和便利性。
摘要由CSDN通过智能技术生成

今天一起说说微服务,之前写docker多服务部署的时候也说微服务,一起说说Spring boot快速开始及核心功能介绍。源码:https://github.com/limingios/netFuture/tree/master/源码/『互联网架构』软件架构-解密电商系统-Spring boot快速开始及核心功能介绍(上)(84)/

11c52a3277cc34ce5ed36e072515aba4.png

(一)Spring boot认知,核心功能

一般的框架出现主要是为了解决问题的。微服务和springboot出现,是一个非常重大的更新,spring已经没落了很久的(也可以说整个java),自从springboot出现spring二次发育第二春。吐糟:java开发起来非常的笨重,没有动态语言go,python,nodejs轻。每次搞java的spring配置一坨一坨的,用技术也需要配置很多,管理很多的配置,开发效率低下。

  • 微架构
  • 1.快速集成
  • 2.开发快速
  • 3.启动快速
  • 4.部署快速
  • 5.测试部署

spring的微架构落地的实现springboot。

  1. Spring Boot是为了简化Spring应用的创建、运行、调试、部署等而出现的,使用它可以做到专注于Spring应用及业务的开发,而无需过多关注XML的配置[理想情况零配置] (0配置只是说说基本不可能,可以通过0配置来配置应用,但是我们应用还是要做一点点的配置)
  2. 简单来说,它提供了一堆Starter POM依赖包,并按照使用习惯解决了一些依赖问题及配置问题[习惯优于约定](反例:契约优先就是定义WebService接口,先定义wsdl的xml,然后在开始写代码。)。
  3. Spring Boot默认使用内嵌的tomcat作为应用服务器,使用logback作为日志记录。
  4. Spring Boot提供了一系列的依赖包,所以需要构建工具的支持:maven 或 gradle。

核心功能

  1. 以jar包方式独立运行(jar -jar xxx.jar) (只需要安装个jdk就可以运行)。
  2. 内嵌Servlet容器(tomcat, jetty),无 需以war包形式部署到独立的servlet容器中 。
  3. 提供starter简化maven依赖包配置。
  4. 自动装配bean(大多数场景) 。
  5. 零配置(理论上),Spring 4.x新特性,提倡使用java配置和注解配置结合而无需xml配置。

(二) springBoot的搭建

  • 官方向导搭建boot应用

https://start.spring.io/springboot的一个搭建的向导。

f4fe767d66055242883ee5556e022347.png
f83879f277d52d33bdb7df672dbe10b2.png

点击Generate Project

9d8639f7d5153bc6fd0157da335a8fad.png

下载的springboot-first解压,只用idea打开

df881358443e0f662801f632e7c13378.png

idea导入完毕

d504007f560c6500598592423a508693.png

新建立包com.idig8.springboot.controller

3aeeff7657cfcc655960b19ac9c2b13c.png

新建立controller

af64d37c9791af26f4f7b6287c588f26.png

编写HelloController

package com.idig8.springboot.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;/** * @program: springboot-first * @description: controller文件编写 * @author: LiMing * @create: 2019-06-04 22:09 **/@Controllerpublic class HelloController { @RequestMapping("/") @ResponseBody public String index(){ return "Hello world!"; }}
4ed8ee00db09025d0ec0de366e4c1985.png

修改SpringbootFirstApplication,增加扫描包

package com.idig8.springboot.springbootfirst;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.ComponentScan;@SpringBootApplication@ComponentScan(basePackages = {"com.idig8.springboot.controller"})public class SpringbootFirstApplication { public static void main(String[] args) { SpringApplication.run(SpringbootFirstApplication.class, args); }}
1f0af67d27c6d3054328bd6142c93085.png

进入SpringbootFirstApplication如下图选择运行

6913c34b84db1569dd3a87ba186b49fc.png

springboot 已经成功启动,端口8080扫描到了对应/ 对应的HelloController的index方法启动时间2秒就启动就可以了。

3bc0053f2d295164c686ee1cb623d090.png

访问:http://127.0.0.1:8080

5b4ca2c593abb8bcb31672ea6c8e8d43.png

从上边的看,是不是感觉做个web开发很简单,1分钟搞定。

  • 普通maven工程搭建boot应用

新建一个普通的maven工程【注意:Spring boot是web工程,但是我们这里只需要建立quickstart即可,因为spring boot内嵌了servlert容器】

707c2da1132bf496f6c36b021c707592.png
44ee7c122f9147a933dfe4c3007aee2c.png
6ea1e17774a9c8271d663f9115597677.png

查看官方文档:https://projects.spring.io/spring-boot/

81b842b3bb10ee07f400ef3973def9f3.png

点击learn-选择版本1.5.10.RELEASE。建议:生产环境中选择稳定的版本

2360c766c1844c76177ed3b2d9a1780a.png

拷贝依赖的父pom到自己的工程pom文件中

org.springframework.boot spring-boot-starter-parent 1.5.10.RELEASEorg.springframework.boot spring-boot-starter-web 
75daf9f7dadaa6b1b1e87d2f9cd5253a.png

从上面的第一个boot项目的pom中拷贝项目构建的内容到当前工程中(以下内容为每个maven项目都必须要的)

UTF-8UTF-81.8org.springframework.boot spring-boot-maven-plugin 
6ec54933a77b75b5efcce618464de3a5.png
bb66b64cc9dca359bd76349ee80d2060.png
d000848e35c173392545dbbad80d8f4c.png

官方文档的例子,尝试启动springboot

8064c7b6b79dde0df542a45a1ad88cdf.png
import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;@RestController@EnableAutoConfigurationpublic class Example { @RequestMapping("/") String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); }}
e1c5b1080734e68f99df735907f43384.png

运行结果

5fac3162a4827d68fe085ba8bb44dbc5.png
  • Starter POMs

1.Spring boot由大量starter组成,每个starter就是一个pom文件,里面包含必要的jar依赖,所以Starter主要是用来简化依赖2.Spring boot支持需要引入其提供的父POM

org.springframework.boot spring-boot-starter-parent 1.5.10.RELEASE

父POM中主要做了两件事情1.所有jar包的版本统一管理。2.所有jar的依赖管理,其中包含springboot 给我们提供的很多的starter启动器。

PS:pom中引入的parent中的spring-boot-starter-parent,进入仓库可以看到对应的里面没有jar包,只有一个pom文件,这个pom文件中有个属性dependencyManagement 这是实现定义好的依赖jar包进行版本管理的管理器。实现都定义好了需要依赖的jar。

(三)统一父POM管理

  • 建立boot-parent工程

首先我们建立一个 boot-parent的maven工程

fb02fa5c0b53f008d821879841b1edbd.png
91cb1027a84494cb44f4bca9eb6fd985.png
46519f2059d5c2cf8178e448b1f76036.png

删除src目录

02000a8a6af4a1637fe8bc438868c8b4.png

然后修改pom.xml。packaging改为为pom格式。

pom

加入dependencyManagement, 同时去掉version, 直接使用父pom中的版本即可。

 org.springframework.boot spring-boot-parent 1.5.10.RELEASEpomimport

加入 build

 org.springframework.boot spring-boot-maven-plugin 

加入properties添加

 UTF-8UTF-81.8

父pom完整代码

<?xml version="1.0" encoding="UTF-8"?>4.0.0com.idig8.springboot springboot-parent 1.0-SNAPSHOTpomvip-springboot-parenthttp://maven.apache.orgUTF-8UTF-81.8org.springframework.boot spring-boot-parent 1.5.10.RELEASEpomimportorg.springframework.boot spring-boot-maven-plugin 
6ea0d89238b0b35e4408f850e275b020.png
  • 创建module-base项目
7f26e100ebd369af631e810c9f920ac2.png
d385b6b59b0186b31c36773a920c20d1.png
13eaa7969e26e42c7ebeb58b53d7fae1.png
864fc37d84014d8c9c14ac17c0dae6dc.png

加入java文件

package com.idig8.springboot;/** * @program: springboot-second * @description: ${description} * @author: LiMing * @create: 2019-06-04 22:42 **/import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;@RestController@EnableAutoConfigurationpublic class Example { @RequestMapping("/") String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); }}

pom文件修改

<?xml version="1.0" encoding="UTF-8"?> springboot-parent com.idig8.springboot1.0-SNAPSHOT4.0.0 com.idig8.springboot-base springboot-basehttp://maven.apache.orgUTF-8UTF-81.8org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test testorg.springframework.boot spring-boot-devtools 

然后访问:http://localhost:8080/

spring boot一个很重要的特点:解决了所有依赖的版本问题。

3c2a245dba7e1b00a9f285ea952da961.png

(四)spring boot 测试

添加测试支持依赖:spring-boot-starter-test

org.springframework.boot

spring-boot-starter-test

test

注意:加入这个依赖之后,junit包就可以不用了,因为test的starter中包含了junit。备注:怎么找到所有的starter。进入官网查询Reference:https://start.spring.io/

fd6306e4515302d60eb8361be4febca5.png

这里面ctrl +f 搜索:starter,就可以看到spring boot中的所有starter

编写测试类

package com.idig8.springboot;import junit.framework.TestCase;import org.junit.Ignore;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import org.springframework.test.context.web.WebAppConfiguration;@Ignore@SpringBootTest(classes=Example.class)@WebAppConfiguration@RunWith(SpringJUnit4ClassRunner.class)public class ExampleTest { @Autowired private Example controller; // @Test public void testHome() { TestCase.assertEquals("Hello World!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值