频道栏目
首页 > 资讯 > 云计算 > 正文

PCF(PivotalCloudFoundry)MetricsReference源码及索引

17-08-04        来源:[db:作者]  
收藏   我要投稿

PCF Metrics Reference Guide

第一次接触这些东西,仅仅是粗糙地做了一个索引,以下解释仅作参考
Jia Feiran
1. MetricsApplication.java

package io.pivotal;
/* 
1. Spring-boot is in https://github.com/spring-projects/spring-boot
2. Springframework-scheduling is in https://github.com/spring-projects/spring-framework/tree/master/spring-context/src/main/java/org/springframework/scheduling
*/
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class MetricsApplication {

    public static void main(String[] args) {
        SpringApplication.run(MetricsApplication.class, args);
    }

}

SpringConfiguration.java

import javax.net.ssl.SSLContext;
//Instances of this class represent a secure socket protocol implementation which acts as a factory for secure socket factories or SSLEngines.
import javax.net.ssl.TrustManager;
//This is the base interface for JSSE trust managers.
import javax.net.ssl.X509TrustManager;
//Instance of this interface manage which X509 certificates may be used to authenticate the remote side of a secure socket.
  //http://javadox.com/org.cloudfoundry/cloudfoundry-client-lib/1.0.4/org/cloudfoundry/client/lib/CloudFoundryClient.html
  import org.cloudfoundry.client.lib.CloudCredentials;
  import org.cloudfoundry.client.lib.CloudFoundryClient;

  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Profile;
  import org.springframework.jmx.support.MBeanServerConnectionFactoryBean;
  //http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jmx/support/MBeanServerConnectionFactoryBean.html
  import org.springframework.mail.javamail.JavaMailSender;
  import org.springframework.mail.javamail.JavaMailSenderImpl;

Package javax.net.ssl https://docs.oracle.com/javase/7/docs/api/javax/net/ssl/package-summary.html

Package org.springframework.context http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/package-summary.html?

定义一个配置类来对bean进行配置。Bean通常被定义在配置文件当中,Bean实例化由Spring的Ioc容器进行管理,Bean的实例可以通过Beanfactory进行访问。

BeanFactory作用

配置、创建、管理Bean对象 维持Bean对象之间的依赖关系 负责Bean对象的生命周期

domain: Adding email notifications and some basic notification rules

以下class里面,大都有对应各个参数的set和get函数。

Application.java

在这个java文件下,仅import java.io.Serializable;,用于序列化对象。保存内存中各种对象的状态。

Attribute.java

import org.apache.commons.lang3.builder.ToStringBuilder;, 该包可以在https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/builder/package-summary.html 中找到。位于commons-lang包应该属于比较基础的操作。

类Attribute中主要有namevalue两个属性。

CloudUser.java

类clouduser里,主要有metadataentity两个私有变量。metadata是Metadata(元数据,见下文),为描述数据属性的信息。entity是一个实体类。

CustomJobMetric.java

类CustomJobMetric里,有私有的jobDetail和customAttributes。jobDetail是JobDetail(见下文), 它定义了Job的实例,包含了Job相关的配置信息。customAttributes是一个ArrayList。

Email.java Adding email notifications and some basic notification rules

这个文件中有import com.fasterxml.jackson.annotation.JsonIgnore;, jackson-annotations的具体位置为 https://github.com/FasterXML/jackson-annotations。 其中 JsonIgnore的位置在 https://github.com/FasterXML/jackson-annotations/blob/master/src/main/java/com/fasterxml/jackson/annotation/JsonIgnore.java 。 Jackson Annotations的文档:https://github.com/FasterXML/jackson-annotations/wiki/Jackson-Annotations 将普通数据与json (JS对象标记)数据互转。

FixedAttribute.java

具有以下变量,描述系统数据

    private String system_healthy;
    private String system_load_1m;
    private String system_swap_percent;
    private String system_swap_kb;
    private String system_cpu_user;
    private String system_disk_ephemeral_inode_percent;
    private String system_disk_ephemeral_percent;
    private String system_disk_system_percent;
    private String system_cpu_sys;
    private String system_disk_persistent_percent;
    private String system_mem_kb;
    private String system_cpu_wait;
    private String system_mem_percent;
    private String system_disk_system_inode_percent;
    private String system_disk_persistent_inode_percent;

JobDetail.java

该类包括depolyment(部署)、job、ip、index等信息。

Metadata.java

UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Foundation, OSF) 的组织在分布式计算环境 (Distributed Computing Environment, DCE) 领域的一部份。UUID 的目的,是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指定。是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的。

日期时间。 时钟序列 全局唯一的IEEE机器识别号,从网卡MAC地址获得,没有网卡以其他方式获得。

该类里具有:

private UUID guid;
private String url;
private Date createDate;
private Date updateDate;

元数据中包含:Guid,Url, CreateDate, Update几个set和get函数?

Rule.java Adding email notifications and some basic notification rules

Java的序列化机制是通过在运行时判断类的serialVersionUID来验证版本一致性的

在类rule里,主要设定了私有的attributeName1、attributeName2、阈值threadshold和message信息。

Total.java

在类total里,有name和value 两个变量。

UserEntity.java

用户主体有以下变量

private boolean admin;
private boolean active;
private String defaultSpaceGuid;
private String username;
private String spacesUrl; 
private String organizationsUrl;
private String managedOrganizationsUrl;
private String billingManagedOrganizationsUrl;
private String auditedOrganizationsUrl;
private String managedSpacesUrl;
private String auditedSpacesUrl;

?

Users.java

在这个类别下面,拥有私有的totalUsers 和 CloudUser(同一个文件夹下面的CloudUser类,见上文) cloudusers的ArrayList。

除了get和set函数还有public void addCloudUsers(CloudUser cloudUser)用以加入云用户

VMMetric.java

VMMetric类下,有JobDetail jobDetail、FixedAttributefixedAttribute和Attribute的动态数组customAttributes

Metrics.java

Metrics类下有两个动态数组vmMetrics和customJobMetrics。

service:Modified the code to skip ssl validation for jmx

ApplicationService.java

import org.cloudfoundry.client.lib.CloudFoundryClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
//reference for springframework is showed in reference

import io.pivotal.domain.Application; //in floder domain, 见上文
import io.pivotal.domain.Total; //in floder domain, 见上文

Docs for Cloud Foundry Java Client Library: https://docs.run.pivotal.io/buildpacks/java/java-client.html

Code for Cloud Foundry Java Client: https://github.com/cloudfoundry/cf-java-client

在ApplicationService类下,有cloudFoundryClient和clientService变量。

方法getApplication()生成并返回一个Application (见上文:domain)的列表。

方法populateAppCounts(List totals)计算并增加App Count, AI’s Count, Running AI’s Count, Diego Apps Count 以及 Warden Apps Count到 totals(Total类见上文domain)中。

BuildpackSerivice.java

该类别下,CloudFoundryClientService(该类别可以在同一个文件夹下的CloudFoundryClientService.java找到)变量clientService getTotalBuildpacks()方法可以算出总数。

CloudFoundryClientService.java

import org.cloudfoundry.client.lib.CloudFoundryClient;
import org.cloudfoundry.client.lib.util.JsonUtil;
import org.cloudfoundry.client.lib.util.RestUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;//The HttpEntity is similar to @RequestBody and @ResponseBody. Besides getting access to the request and response body, HttpEntity (and the response-specific subclass ResponseEntity) also allows access to the request and response headers.

import org.springframework.http.HttpHeaders;//request header
import org.springframework.http.HttpMethod;//for the HTTP request method
import org.springframework.http.ResponseEntity;//ResponseEntity provides a builder-style API to guide controller methods towards the preparation of server-side responses, e.g. ResponseEntity.ok().
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;//The names of RestTemplate methods follow a naming convention, the first part indicates what HTTP method is being invoked and the second part indicates what is returned.RestTemplate provides higher level methods that correspond to each of the six main HTTP methods that make invoking many RESTful services a one-liner and enforce REST best practices.

import io.pivotal.domain.Metadata;//in floder omain,见上文

@Service//注解
Doc for Cloud Foundry Java Client Library https://docs.cloudfoundry.org/buildpacks/java/java-client.html

Github for Cloud Foundry Java Client Library https://github.com/cloudfoundry/cf-java-client

org.springframework.http.HttpEntity https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/

RestTemplate https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/

JsonUtil http://javadox.com/org.cloudfoundry/cloudfoundry-client-lib/1.0.4/org/cloudfoundry/client/lib/util/JsonUtil.html

函数

public Map getResponseMap(String path)返回了一个关于response的map public List<>> getAllResources(Map respMap) respMap里关于resources以及next_url的内容被加入 private String addPageOfResources(String nextUrl, List<>> allResources)添加resources并返回respMap里关于next_url的内容 public Metadata getMeta(Map resource) 通过resource设定并返回一个元数据Metadata public Integer getTotalResults(Map respMap)获得respMap中的”total_results”信息 private RestTemplate getRestTemplate() 生产并返回一个RestTamplate protected String getUrl(String path)通过cloudFoundryClient获取Url private ResponseEntity getResponse(String path)设定并返回response private static Date parseDate(String dateString)格式化并返回日期 [带异常处理]

?

EmaiSerivice.java

   import org.springframework.beans.factory.annotation.Autowired;
   import org.springframework.mail.SimpleMailMessage;
   //The org.springframework.mail package is the root level package for the Spring Framework’s email support. The central interface for sending emails is the MailSender interface; a simple value object encapsulating the properties of a simple mail such as from and to (plus many others) is the SimpleMailMessage class.
   import org.springframework.mail.javamail.JavaMailSender;//The org.springframework.mail.javamail.JavaMailSender interface adds specialized JavaMail features such as MIME message support to the MailSender interface (from which it inherits).
   import org.springframework.stereotype.Service;
   import org.springframework.util.StringUtils;
   //reference for springframework is showed in reference
   import io.pivotal.domain.Email;
    //in floder domain, 见上文

   @Service
   public class EmailService {

    @Autowired
    JavaMailSender javaMailSender;//from spring

    private Email email = new Email();// from domain

    public void sendEmail(String message) {
        if (email != null && email.isEmailConfigured() && !StringUtils.isEmpty(message)) {
            SimpleMailMessage mailMessage = new SimpleMailMessage();
            mailMessage.setTo(email.getToAddr()); 
            mailMessage.setReplyTo(email.getReplyToAddr()); //设置发信人
            mailMessage.setSubject(email.getSubject());//创建MIMEMessage
            mailMessage.setText(message);
            javaMailSender.send(mailMessage);
        }
    }
   //get and set
    public Email getEmail() {
        return email;
    }

    public void setEmail(Email email) {
        this.email = email;
    }

   }

EventSerivice.java

创建CloudFoundryClientService变量clientService.

函数:对于app来说

public Integer getTotalAppCreateEvents()调用CloudFoundryClientService中getTotalResults获得create总计数。 public Integer getTotalAppDeleteEvents()获得delete总计数 public Integer getTotalAppCrashEvents()获得crash总计数 public Integer getTotalAuthorizedSSHEvents()获得ssh-authorized总计数 public Integer getTotalUnAuthorizedSSHEvents()获得ssh-unauthorized总计数 public Integer getTotalAppStartEvents()获得start总计数 public Integer getTotalAppStopEvents()获得stop总计数 public Integer getTotalAppUpdateEvents()获得update总计数

?

MetricService.java

/*
javax.management提供 Java Management Extensions 的核心类。 Java Management Extensions (JMXTM) API 是一个用于管理和监视的标准 API。典型用途包括: 查询并更改应用程序配置 累积有关应用程序行为的统计并使其可用 通知状态更改及错误状况。 JMX API 还可以作为解决方案的一部分来管理系统、网络等。 API 包括远程访问,因此,远程管理程序可以基于这些目的与正在运行的应用程序交互。
JMX API 的基本概念是 MBean。MBean 是表示资源的指定托管对象。它有一个管理接口,包括以下内容:
- 可以读取和/或写入的指定名称和类型的属性
- 可以调用的指定名称和类型的操作
- 可以由 MBean 发送的指定类型的通知。
*/
import javax.management.MBeanAttributeInfo;
//Describes an MBean attribute exposed for management.
import javax.management.MBeanInfo;
//Describes the management interface exposed by an MBean; that is, the set of attributes and operations which are available for management operations.
import javax.management.MBeanServerConnection;
//This interface represents a way to talk to an MBean server, whether local or remote.
import javax.management.ObjectInstance;
//Used to represent the object name of an MBean and its class name.
import javax.management.ObjectName;
//Represents the object name of an MBean, or a pattern that can match the names of several MBeans.

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
//Indicates that a component is eligible for registration when one or more specified profiles are active.
import org.springframework.stereotype.Service;
// http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Service.html
import org.springframework.util.StringUtils;

//in domain
import io.pivotal.domain.Attribute;
import io.pivotal.domain.CustomJobMetric;
import io.pivotal.domain.FixedAttribute;
import io.pivotal.domain.JobDetail;
import io.pivotal.domain.Metrics;
import io.pivotal.domain.VMMetric;

   -  Package javax.management http://docs.oracle.com/javase/7/docs/api/javax/management/package-summary.html

   -  Package org.springframework.context.annotation https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/package-summary.html

   -  ```java
      public class ObjectInstance
  Used to represent the object name of an MBean and its class name. If the MBean is a Dynamic MBean the class name should be retrieved from the `MBeanInfo` it provides.

getAttributes() 返回所有属性的列表,这些属性的存在是根据 MBean 接口中是否存在 getName、isName 或 setName

函数

private CustomJobMetric populateCustomJobMetrics(ObjectName objectName, JobDetail job) throws Exception CustomJobMetric这个类可以在上文domain中找到,通过getAttributes()获取属性列表作为attributes。设定属性并返回customJobMetric。

private VMMetric populateVMMetrics(ObjectName objectName, JobDetail jobDetail) throws Exception 设定属性并返回VMMetric(in domain)

private void populateObject(Object obj, String key, String value) throws Exception ja反射使用:如果字段是私有的,那么必须要对这个字段设置setAccessible(true),之后用value设置obj

private void populateMetrics(ObjectInstance object, Metrics metrics) throws Exception 施行populateObject函数,设置metrics

public Metrics getMetrics() 通过queryMBeans (Gets MBeans controlled by the MBean server. https://docs.oracle.com/javase/7/docs/api/javax/management/MBeanServerConnection.html)获取object信息

OrgService.java

https://github.com/cloudfoundry/cf-java-client Cloud Foundry Java Client

函数:

public List getOrgs() 通过CloudFoundryClient获取organization信息并返回。

public Integer getTotalOrgs() 通过CloudFoundryClientService获取organization总数。

RouteService.java

public Integer getTotalRoutes()通过CloudFoundryClientService获取routes总数。

ServicesService.java

public Integer getTotalServiceBrokers()获得service_brokers的个数。

public Integer getTotalServices()获得service的总个数。

public Integer getTotalServiceInstances()获得service_instances的总个数。

SpaceService.java

public List getSpaces()通过CloudFoundryClient获取spaces信息并返回。

public Integer getTotalSpaces() 获取spaces个数。

TotalsService.java

public List getTotals() 返回的list的类型total是domain里的,这里通过各类Serivice存入了Orgs, Spaces, Users, Buildpacks,Serbices, Service Brokers, Service Instances, App Create Events, App Delete Events, App Authorized SSH Events,App UnAuthorized SSH Events, App Start Events, App Stop Events, App Update Events, App Crash Events的总数信息。调用populateAppCounts()(这个函数在ApplicationService中可以找到,见上文),计算并增加App Count, AI’s Count, Running AI’s Count, Diego Apps Count 以及 Warden Apps Count到 totals。

UserService.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//以下import可以在domain里找到(见上文domain)
import io.pivotal.domain.CloudUser;
import io.pivotal.domain.Metadata;
import io.pivotal.domain.UserEntity;
import io.pivotal.domain.Users;

public Users getAllUsers()通过CloudFoundryClientService(见上文)获取user信息并返回user(类型见上文domain)

public Integer getTotalUsers()调用CloudFoundryClientService(见上文)中getTotalResults获取user总数信息

private Users getCloudUsers(List<>> allResources)从allResources通过Users中addCloudUser获取云用户信息并返回user

private CloudUser getCloudUser(Map resource)从resource里通过CloudFoundryClientService(见上文)中getMeta()与getEntity获取并设定云用户信息,并且返回云用户。

private UserEntity getEntity(Map resource) 设定userEntity信息并返回。

controller: Modified the code to skip ssl validation for jmx

https://github.com/pivotalservices/foundation-metrics/tree/master/metrics/src/main/java/io/pivotal/controller

ApplicationController.java Code to fetch metrics for a PCF foundation
package io.pivotal.controller;
import java.util.List;// be used to insert the required placeholders and pass in the values during the statement execution.
/*
1. springframework.beans is in https://github.com/spring-projects/spring-framework/tree/master/spring-beans
2. springframework.web is in https://github.com/spring-projects/spring-framework/tree/master/spring-web/src/main/java/org/springframework/web
3. 
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.pivotal.domain.Application;
import io.pivotal.service.ApplicationService;
@RestController
@RequestMapping(value = "apps")

public class ApplicationController {

    @Autowired
    ApplicationService applicationService;

    @CrossOrigin
    @RequestMapping(method=RequestMethod.GET)
    public List getApps() {
        return applicationService.getApplications();
    }
}

? public List getApps()返回一个Application的列表

MetricsController.java Code to fetch metrics for a PCF foundation
package io.pivotal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;

import org.springframework.web.bind.annotation.CrossOrigin;
//Marks the annotated method or type as permitting cross origin requests.
import org.springframework.web.bind.annotation.RequestMapping;
//Annotation for mapping web requests onto specific handler classes and/or handler methods.
import org.springframework.web.bind.annotation.RequestMethod;
//Java 5 enumeration of HTTP request methods.
import org.springframework.web.bind.annotation.RestController;
//A convenience annotation that is itself annotated with @Controller and @ResponseBody.

//domain.Metrics 和 service.MetricService 是相对路径,可以在pivatolservices里(io/pivotal)中找到
import io.pivotal.domain.Metrics;
import io.pivotal.service.MetricService;

@Profile("jmx")
// The @Profile annotation allows you to indicate that a component is eligible for registration when one or more specified profiles are active. Using our example above, we can rewrite the dataSource configuration as follows:

@RestController
//Creating REST Controllers with the @RestController annotation
@RequestMapping(value = "metrics")
//You use the @RequestMapping annotation to map URLs such as /appointments onto an entire class or a particular handler method. 
public class MetricsController {
    @Autowired
    MetricService metricService;

    @CrossOrigin
    @RequestMapping(method = RequestMethod.GET)
    public Metrics getAllMetrics() {
        Metrics metrics = metricService.getMetrics();
        return metrics;
    }
}

? public Metrics getAllMetrics()

OrgController.java

public List getOrgs()通过OrgService(见上文Service)获取organization信息并返回。

SettingsController.java

package io.pivotal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
//Marks the annotated method or type as permitting cross origin requests.
import org.springframework.web.bind.annotation.RequestBody;
//Annotation indicating a method parameter should be bound to the body of the web request.
import org.springframework.web.bind.annotation.RequestMapping;
//Annotation for mapping web requests onto specific handler classes and/or handler methods.
import org.springframework.web.bind.annotation.RequestMethod;
//Java 5 enumeration of HTTP request methods.
import org.springframework.web.bind.annotation.RestController;
//A convenience annotation that is itself annotated with @Controller and @ResponseBody.

//domain.Email 和 service.EmailService 是相对路径,可以在domain和service中找到
import io.pivotal.domain.Email;
import io.pivotal.service.EmailService;

@RestController
@RequestMapping(value = "settings")
public class SettingsController {

@Autowired
EmailService emailService;

@CrossOrigin
@RequestMapping(value = "mail", method = RequestMethod.POST)
public Email configureEmail(@RequestBody Email email) {
    emailService.setEmail(email);
    return emailService.getEmail();
}

@CrossOrigin
@RequestMapping(value = "mail", method = RequestMethod.GET)
public Email getEmail() {
    return emailService.getEmail();
}

}
doc Package org.springframework.web.bind.annotation http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/package-summary.html public Email configureEmail(@RequestBody Email email) 设置emailService中的email并且返回email。EmailService见上文service部分 public Email getEmail()获取email信息。

SpaceController.java

package io.pivotal.controller;

import java.util.List;

import org.cloudfoundry.client.lib.domain.CloudSpace;
//public class CloudSpace extends CloudEntity

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
//Marks the annotated method or type as permitting cross origin requests.
import org.springframework.web.bind.annotation.RequestMapping;
//Annotation for mapping web requests onto specific handler classes and/or handler methods.
import org.springframework.web.bind.annotation.RequestMethod;
//Java 5 enumeration of HTTP request methods.
import org.springframework.web.bind.annotation.RestController;
//A convenience annotation that is itself annotated with @Controller and @ResponseBody.

import io.pivotal.service.SpaceService;//in Service

@RestController
@RequestMapping(value = "spaces")
public class SpaceController {

@Autowired
SpaceService spaceService;

@CrossOrigin
@RequestMapping(method = RequestMethod.GET)
public List getSpaces() {
    return spaceService.getSpaces();
}
}
public List getSpaces()获取space信息.SpaceService在上文service中可以找到

TotalController.java

package io.pivotal.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
//Marks the annotated method or type as permitting cross origin requests.
import org.springframework.web.bind.annotation.RequestMapping;
//Annotation for mapping web requests onto specific handler classes and/or handler methods.
import org.springframework.web.bind.annotation.RequestMethod;
//Java 5 enumeration of HTTP request methods.
import org.springframework.web.bind.annotation.RestController;
//A convenience annotation that is itself annotated with @Controller and @ResponseBody.

import io.pivotal.domain.Total;//in domain
import io.pivotal.service.TotalsService;//in service

@RestController
@RequestMapping(value = "totals")
public class TotalController {

@Autowired
TotalsService totalsService;

@CrossOrigin
@RequestMapping(method = RequestMethod.GET)
public List getTotals() {
    return totalsService.getTotals();
}

}
public List getTotals() 获取totals总个数。getTotals可以在service.TotalsService(见上文)中找到

UserController.java

package io.pivotal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
//Marks the annotated method or type as permitting cross origin requests.
import org.springframework.web.bind.annotation.RequestMapping;
//Annotation for mapping web requests onto specific handler classes and/or handler methods.
import org.springframework.web.bind.annotation.RequestMethod;
//Java 5 enumeration of HTTP request methods.
import org.springframework.web.bind.annotation.RestController;
//A convenience annotation that is itself annotated with @Controller and @ResponseBody

import io.pivotal.domain.Users;//in domain
import io.pivotal.service.UserService;//in service

@RestController
@RequestMapping(value = "users")
public class UserController {

@Autowired
UserService userService;

@CrossOrigin
@RequestMapping(method = RequestMethod.GET)
public Users getUsers() {
    return userService.getAllUsers();
}
}
public Users getUsers() 获取user信息并返回user

References

Pivotal Software Inc [github]: https://github.com/pivotalsoftware Pivotal doc. http://docs.pivotal.io

Cloud Foundry CF

https://docs.cloudfoundry.org document for cloudfundory https://run.pivotal.io Pivatol Cloud Foundary [github]: https://github.com/pivotal-cf Cloud Foundry [github] https://github.com/cloudfoundry/

Spring, a Java development framework

Guides https://spring.io/guides Spring Github https://github.com/spring-projects Spring Framework Reference Documentation https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/ The Spring Framework [github] https://github.com/spring-projects/spring-framework
相关TAG标签
上一篇:IntersectionOfTwoLinkedList
下一篇:mysql - galera 故障恢复
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站