Third service providers and service consumers

Source: Internet
Author: User
Tags bind xmlns aliyun
I. The concept of service providers and service consumers

Service provider: The callee of the service (that is, a service that serves other services)
Service consumer: The caller of a service (that is, a service that relies on other services) Ii. writing a service provider (auto-build framework: http://start.spring.io/) Build Service provider framework import projects into the IDE
Configuring the Maven repository to modify MAVEN's original settings file:

To configure the local warehouse path:

<localRepository>E:\JAVA\apache-maven-3.3.9\conf\</localRepository>
Configure the image of Alibaba Cloud
<mirror>
  <id>nexus-aliyun</id>
  <mirrorOf>central</mirrorOf>
  <name >nexus aliyun</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
Code Controller:
Package Cn.com.yeexun.cloud.controller;

Import org.springframework.beans.factory.annotation.Autowired;
Import org.springframework.web.bind.annotation.GetMapping;
Import org.springframework.web.bind.annotation.PathVariable;
Import Org.springframework.web.bind.annotation.RestController;
Import Cn.com.yeexun.cloud.dao.UserDao;
Import Cn.com.yeexun.cloud.entity.User;

@RestController public
class Usercontroller {

  @Autowired
  private Userdao Userdao;

  @GetMapping ("/simple/{id}") Public
  User FindByID (@PathVariable Long id)
  {
    return Userdao.findone (ID) ;
  }
}
Dao:
Package Cn.com.yeexun.cloud.dao;

Import org.springframework.data.jpa.repository.JpaRepository;
Import org.springframework.stereotype.Repository;
Import Cn.com.yeexun.cloud.entity.User;

@Repository public
Interface Userdao extends Jparepository<user, long> {
}
Entity:
Package cn.com.yeexun.cloud.entity;
Import Java.math.BigDecimal;
Import Javax.persistence.Column;
Import javax.persistence.Entity;
Import Javax.persistence.GeneratedValue;
Import Javax.persistence.GenerationType;

Import Javax.persistence.Id;
    
    @Entity public class User {@Id @GeneratedValue (strategy = Generationtype.auto) Private long Id;
    
    @Column private String username;
    
    @Column private String name;
    
    @Column private short age;
    
    @Column private BigDecimal balance;
    Public long GetId () {return id;
    } public void SetId (long id) {this.id = ID;
    } public String GetUserName () {return username;
    } public void Setusername (String username) {this.username = username;
    } public String GetName () {return name;
    } public void SetName (String name) {this.name = name;
    } public short Getage () {return age; } public void SETage (short age) {this.age = age;
    } public BigDecimal GetBalance () {return balance;
    } public void Setbalance (BigDecimal balance) {this.balance = balance;
 }
}
Apllication Startup class:
Package Cn.com.yeexun.cloud;

Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication public
class Micoroservicesimpleprovideruserapplication {public

    static void main ( String[] args) {
     springapplication.run (micoroservicesimpleprovideruserapplication.class, args);
    }
}
application.yml:
Server:
  port:7900

Spring:
  JPA:
    generate-ddl:false #启动时是否生成ddl语句
    show-sql:true
    Hibernate :
      ddl-auto:none  #启动时不做ddl语句处理
  datasource:
    platform:h2
    schema:classpath:schema.sql
    Data:classpath:data.sql

Logging: Level
  :
    root:info
    org.hibernate:  INFO
    Org.hibernate.type.descriptor.sql.BasicBinder:TRACE
    Org.hibernate.type.descriptor.sql.BasicExtractor: TRACE
    Cn.com:DEBUG
Data.sql:
INSERT into user (ID, username, name, age, Balance) VALUES (1, ' user1 ', ' Zhang Yi ', ' 100.00 ');
INSERT into user (ID, username, name, age, Balance) values (2, ' user2 ', ' Wang II ', ' 101.00 ');
INSERT into user (ID, username, name, age, Balance) VALUES (3, ' user3 ', ' Lie Triple ', 102.00);
INSERT into user (ID, username, name, age, Balance) values (4, ' user4 ', ' ma Four ', 24, 103.00);
Schema.sql:
Drop table user if exists;
CREATE TABLE User (
    ID bigint generated by default as identity, 
    username varchar (+),
    name varchar
    , Age int (3),
    balance Decimal (10,2),
    primary key (ID) 
);
Pom.xml:
<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0/http Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupid>cn.com.y Eexun.cloud</groupid> <artifactId>micoroservice-simple-provider-user</artifactId> <version& Gt;0.0.1-snapshot</version> <packaging>jar</packaging> <name>micoroservice-simple-provid Er-user</name> <description>demo Project for Spring boot</description> <parent> & Lt;groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</ Artifactid> <version>1.5.10.RELEASE</version> <relativePath/> <!--lookup parent F Rom Repository--</

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.