Leopard label simplifies Spring configuration, leopard Label spring

Source: Internet
Author: User

Leopard label simplifies Spring configuration, leopard Label spring
Leopard label simplifies Spring configuration learn how to use Leopard label simplifies Spring Configuration

This guide will guide you through using the Leopard label to simplify Spring configuration.

How to complete this guide

You can start from scratch and complete each step, or you can bypass the basic setup steps you are already familiar. Either way, you can finally get the code that can work.

1. XML file header configuration

The Leopard label is a configuration method based on XML Schema. It aims to simplify the configuration method. Add the following content to the XML file header:
Xmlns: leopard = "http://www.leopard.io/schema/leopard.pdf ".
Xsi: schemaLocation = http://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd"

2. <leopard: component-scan/>

Similar By default, the Bean name rule defined by Leopard is used, and the timer is automatically registered (Bean that implements the io. leopard. burrow. Timer. timer interface ).

Example

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:leopard="http://www.leopard.io/schema/leopard"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    http://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd">    <leopard:component-scan base-package="io.leopard.guides" /></beans>

Parameter description
base-package: Spring Bean package path

3. <leopard: jdbc/>

MySQL Data Source definition.

Example

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:leopard="http://www.leopard.io/schema/leopard"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    http://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd">    <leopard:jdbc id="jdbc" host="112.126.75.27" database="example" user="example" password="leopard" /></beans>

Parameter description
id: Bean name. We recommend that you use id = "jdbc" when there is only one database, and use database name + "Jdbc" when there are multiple databases"
host: The host or IP address of the MySQL server. placeholders can also be used.
database: Database Name
user: Database username
password: Database Password
port: Database port. The default value is 3306.
maxPoolSize: Maximum number of connections in the connection pool. The default value is 15.
dataSourceId: DataSource Bean name. <leopard: jdbc/> A DataSource Bean is automatically created and can be used for other purposes. The default name is jdbcId + "DataSource ".

4. <leopard: redis/>

Redis Data Source definition.

Example

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:leopard="http://www.leopard.io/schema/leopard"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    http://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd">    <leopard:redis id="redis" server="112.126.75.27:6311" /></beans>

Parameter description
id: Bean name
server: MySQL server host (IP) + port, for example, "112.126.75.27: 6311"
maxActive: Maximum number of connections in the connection pool. The default value is 128.
timeout: Timeout time, in milliseconds. The default value is 3000 milliseconds.
initialPoolSize: The default number of initialized connections in the connection pool. The default value is 1.
enableBackup: Whether to enable automatic backup (that is, run bgsave to save the data). By default, automatic backup is disabled.
backupTime: Backup time, in the format of "mm: hh". The default value is 04:01. (Backup starts at every day)

Summary

Congratulations! You have learned to use the Leopard label to simplify Spring configurations. Good luck.

Related Article

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.