Deploying the Spring Boot Application

Source: Internet
Author: User

Recently has been studying the essence of the company's structure, the company project is generally divided into three modules: ****-api, ****-data-access, ****-cms.

-API uses the spring Boot Micro service concept to provide interface services for other projects.

The return values for all interfaces of the API service are returned in the following structure:

{
     status:200, message
     : "OK",
     entity: {}
}
Status is the HTTP status code, the message is the status description, entity for the specific return data, can be an object or an array.

-data-access is the data access layer, which operates ES and MySQL through the SPIRNG data encapsulation method.

-cms is the encapsulation of the business logic of this project.

After the ****-API has finished writing the interface for other items, the main function is run locally, and the interface can be successfully published locally.

Package com.letv.autostore;

Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;
Import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
Import Org.springframework.context.annotation.ImportResource;


@SpringBootApplication (Exclude={elasticsearchautoconfiguration.class})
@ImportResource ("${ Spring.config.path} ") Public
class Autoapiapplication {public

    static void Main (string[] args) {
        Springapplication.run (Autoapiapplication.class, args);
    }
After the local test passes, the ****-API project is packaged into a jar through the MAVEN Package command.

Here we will explain how to deploy the Spring Boot Micro service on a Linux server:

1. We need to/usr/local the directory to create a ****-API folder;

2. The folder file is as follows: Application.yml ****-api-0.0.1.jar ehcache.xml start.sh;

Basic configuration for Tomcat, spring, log, and es in 3.APPLICATION.YML:

Server:
  port:8080
  Tomcat:
    max-threads:500
    accesslog:
      enabled:true
      directory:./logs Pattern
      : '%h%t%m '%u '%s%b%d '
      prefix:localhost_access
      suffix:. Log

Spring:
  config:
    path : Classpath:applicationContext.xml
  DataSource:
    Username: * * *
    Password: * * *
    url:jdbc:mysql:/ /**.**.**.**:3306/****?useunicode=true&characterencoding=utf-8
    initialsize:3
    maxactive:50
    minevictableidletimemillis:1800000
    timebetweenevictionrunsmillis:60000
    maxwait:10000
  ehcache:
    Name:ehcache
    config:
      path:/usr/local/****-api/ehcache.xml
Logging:
  path:./logs
  Level:
    org.springframework:info
    
es:
  nodes: **.**.**.**:9300
  cluster: ****-****-****
4.ehcache.xml for Ehcache cache related configuration:
<ehcache xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation= ". /config/ehcache.xsd "> <diskstore path=" java.io.tmpdir "/> <cachemanagerpeerproviderfactory class=" net. Sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory "properties=" Connect=tcp (bind_addr=**.** . **.**;bind_port=7800): tcpping (initial_hosts=**.**.**.**.**[7801];p ort_range=10): MERGE2 (min_interval=3000;max_ interval=5000): Fd_all (interval=5000;timeout=20000): FD (timeout=5000;max_tries=48;): Verify_suspect (timeout=1500) : Pbcast.
			Nakack (use_mcast_xmit=false;retransmit_timeout=100,200,300,600,1200,2400,4800;discard_delivered_msgs=true): Pbcast. Stable (stability_delay=1000;desired_avg_gossip=20000;max_bytes=0): Pbcast. GMS (join_timeout=5000;print_local_addr=false;) "propertyseparator=":: "/> <defaultcache maxElementsInMem Ory= "10000" eternal= "false" timetoidleseconds= "the Timetoliveseconds="ementsondisk= "1000000" diskexpirythreadintervalseconds= "memorystoreevictionpolicy=" "LRU" > </defaul tcache> <cache name= "Ehcache" maxelementsinmemory= "100000" eternal= "false" t imetoidleseconds= "1800" timetoliveseconds= "1800" overflowtodisk= "false" Ma xelementsondisk= "1000000" diskpersistent= "false" copyonread= "true" diskexp irythreadintervalseconds= "memorystoreevictionpolicy=" "LRU" > <cacheeventlistenerfactory C lass= "Net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" properties= "replicateasynchronously= True, Replicateputs=true,replicateupdates=true, Replicateupdatesviacopy=false, replicateremovals=true "/> </
 Cache> </ehcache>
5.start.sh the shell script written for running spring boot:
Java-server-xms2g-xmx2g-jar Auto-api-0.0.1.jar &
After we enter the/usr/local/****-api folder, we run./start.sh can start the Spring boot application on the Linux server.

After successful interface deployment, we can test whether the interface can be invoked successfully via Google's postman plugin.

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.