Springboot framework and springboot microframework

Source: Internet
Author: User

Springboot framework and springboot microframework

This article mainly shares why the Springboot framework is so popular and how to build a Springboot framework.

Let's first understand what spring boot is and what it is used. I started to contact and checked a lot of information. I understood some of my own mistakes and expected to correct them. At the beginning, I learned that springboot simplifies framework setup and is ready for use out-of-the-box. Developers do not have to worry about dependency conflicts between jar package versions. The basic 0 configuration file can improve our development efficiency. It simplifies coding, simplifies configuration, simplifies deployment, and simplifies monitoring. Simplified the process of using Spring. I personally think that this item is simple in configuration. maven can automatically download it by adding relevant dependencies to the pom. xml file. It is mainly reflected in the significant improvement in development efficiency and deployment efficiency.

Next we will start to build a Springboot project.

I am using eclipse and installed the STS plug-in:

1. In eclipse: Help-> Eclipse Marketplace-> Popular-> STS, and then install.

2. Create a project: File-> new-> other

Find Spring, select Spring Starter Project, and Next

Take a project name here and click Next.

3. next, select pom. for xml dependency, you can select what you need to use. I have selected a few items here. If there are any selected items, You can manually add them in pom after the project is created. (Your site you call the shots)

4. Click Next-> Finish. In this way, the project is created.

5. Next we will write a helloworld

Package com. example; import org. springframework. boot. springApplication; import org. springframework. boot. autoconfigure. enableAutoConfiguration; import org. springframework. web. bind. annotation. requestMapping; import org. springframework. web. bind. annotation. restController; @ RestController @ EnableAutoConfiguration // @ SpringBootApplication // indicates the startup configuration Entry public class DemoBogApplication {@ RequestMapping ("/") // @ RequestM The apping annotation provides routing information, which tells Spring that any HTTP request from the "/" path should be mapped to the home method String home () {return "Hello World! ";}Public static void main (String [] args) throws Exception {SpringApplication. run (DemoBogApplication. class, args );}}

6. Write the port and database configuration information in application. properties.

Server. port = 8050 // port number spring. datasource. url = jdbc: oracle: thin: // localhost: 1521/orclspring. datasource. username = wwtspring. datasource. password = 123456spring. datasource. driver-class-name = oracle. jdbc. oracleDriverspring. jpa. properties. hibernate. hbm2ddl. auto = create-drop

7. Run: Right-click the project Run As-> Spring Boot App

8. Access

In this way, the Springboot project of helloworld is created.

Finally, let's extend it to Druid. I found it very good when I was working on the Springboot project connection pool. below is my configuration. If you are interested, please take a look.

1. First add the dependency in the pom file:

2. application. properties: the Derby embedded database is used here.

server.port=8070spring.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.datasource.url=jdbc:derby://192.168.1.109:1527/AgentcharacterEncoding=utf-8spring.datasource.driver-class-name=org.apache.derby.jdbc.ClientDriverspring.jpa.properties.hibernate.hbm2ddl.auto=nonespring.mvc.view.prefix=/spring.mvc.view.suffix=.jspspring.datasource.initialSize=5spring.datasource.minIdle=5spring.datasource.maxActive=20spring.datasource.maxWait=60000spring.datasource.timeBetweenEvictionRunsMillis=60000spring.datasource.minEvictableIdleTimeMillis=300000spring.datasource.validationQuery=SELECT 1 FROM DUALspring.datasource.testWhileIdle=truespring.datasource.testOnBorrow=falsespring.datasource.testOnReturn=false

In this way, the connection pool is ready.

Other druid knowledge:

Druid Introduction

Druid is a JDBC component, which consists of three parts:

  • DruidDriver agent Driver, which provides a plug-in system based on the Filter-Chain mode.
  • DruidDataSource efficient and manageable database connection pool.
  • SQLParser

What can Druid do?

  • It can monitor the database access performance. Druid provides a powerful built-in StatFilter plug-in that can calculate the SQL Execution performance in detail, which is helpful for online analysis of database access performance.
  • Replace DBCP and C3P0. Druid provides an efficient, powerful, and scalable database connection pool.
  • Database Password Encryption. Directly write the database password in the configuration file. This is a bad behavior and may cause security problems. Both DruidDruiver and DruidDataSource support PasswordCallback.
  • SQL Execution log. Druid provides different logfilters that support Common-Logging, Log4j, and JdkLog. You can select the corresponding LogFilter as needed to monitor the database access of your application.
  • Extended JDBC: If you want to program the JDBC layer, you can use the Filter-Chain mechanism provided by Druid to conveniently compile the extended JDBC layer plug-in.
Druid is a database connection pool first, but it is not just a database connection pool. It also contains a ProxyDriver, a series of built-in JDBC component libraries, and an SQL Parser. Druid supports all JDBC-compatible databases, including Oracle, MySql, Derby, Postgresql, SQL Server, and H2. Druid has made special optimizations for Oracle and MySql, such as optimizing the PS Cache memory usage of Oracle and optimizing the ping detection of MySql. Druid has obvious advantages in monitoring, scalability, stability and performance. Druid provides an extended API in the Filter-Chain mode. You can write a Filter to intercept any method in JDBC and do anything on it, for example, performance monitoring, SQL audit, username and password encryption, and logs.

 

References: http://blog.csdn.net/blueheart20/article/details/52384032

     

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.