Spring MVC / Rest是否有自己的默认连接池?

时间:2017-04-24 14:26:04

标签: spring-mvc connection-pooling spring-rest

我开发了Spring Rest应用程序。我没有为任何特定的连接池添加代码。我正在考虑HikariCP,boneCP或cp30。

有人告诉我,Spring MVC / Rest有自己的内部连接池,所以即使我不实现任何自己的连接,也不会有任何问题。

我尝试在互联网上找到但有一些疑问。请澄清。

1 个答案:

答案 0 :(得分:0)

不,Spring没有默认连接池,它使用Web服务器[Tomcat]线程请求处理,并且大量使用Threadlocal但是对于数据库操作,您可以使用它们中的任何一个,弹簧引导使用公共池作为默认值但添加其他配置会覆盖其他配置。 Tomcat在春季启动:

server.tomcat.accept-count= # Maximum queue length for incoming connection requests when all possible request processing threads are in use.
    server.tomcat.accesslog.buffered=true # Buffer output such that it is only flushed periodically.
    server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute.
    server.tomcat.accesslog.enabled=false # Enable access log.
    server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in log file name.
    server.tomcat.accesslog.pattern=common # Format pattern for access logs.
    server.tomcat.accesslog.prefix=access_log # Log file name prefix.
    server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time.
    server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for IP address, Hostname, protocol and port used for the request.
    server.tomcat.accesslog.rotate=true # Enable access log rotation.
    server.tomcat.accesslog.suffix=.log # Log file name suffix.
    server.tomcat.additional-tld-skip-patterns= # Comma-separated list of additional patterns that match jars to ignore for TLD scanning.
    server.tomcat.background-processor-delay=30 # Delay in seconds between the invocation of backgroundProcess methods.
    server.tomcat.basedir= # Tomcat base directory. If not specified a temporary directory will be used.
    server.tomcat.internal-proxies=10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
            192\\.168\\.\\d{1,3}\\.\\d{1,3}|\\
            169\\.254\\.\\d{1,3}\\.\\d{1,3}|\\
            127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
            172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
            172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
            172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
    server.tomcat.max-connections= # Maximum number of connections that the server will accept and process at any given time.
    server.tomcat.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.
    server.tomcat.max-threads=0 # Maximum amount of worker threads.
    server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
    server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
    server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
    server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL.
    server.tomcat.redirect-context-root= # Whether requests to the context root should be redirected by appending a / to the path.

for Data Source:

# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.continue-on-error=false # Do not stop if an error occurs while initializing the database.
spring.datasource.data= # Data (DML) script resource references.
spring.datasource.data-username= # User of the database to execute DML scripts (if different).
spring.datasource.data-password= # Password of the database to execute DML scripts (if different).
spring.datasource.dbcp2.*= # Commons DBCP2 specific settings
spring.datasource.driver-class-name= # Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
spring.datasource.generate-unique-name=false # Generate a random datasource name.
spring.datasource.hikari.*= # Hikari specific settings
spring.datasource.initialize=true # Populate the database using 'data.sql'.
spring.datasource.jmx-enabled=false # Enable JMX support (if provided by the underlying pool).
spring.datasource.jndi-name= # JNDI location of the datasource. Class, url, username & password are ignored when set.
spring.datasource.name=testdb # Name of the datasource.
spring.datasource.password= # Login password of the database.
spring.datasource.platform=all # Platform to use in the schema resource (schema-${platform}.sql).
spring.datasource.schema= # Schema (DDL) script resource references.
spring.datasource.schema-username= # User of the database to execute DDL scripts (if different).
spring.datasource.schema-password= # Password of the database to execute DDL scripts (if different).
spring.datasource.separator=; # Statement separator in SQL initialization scripts.
spring.datasource.sql-script-encoding= # SQL scripts encoding.
spring.datasource.tomcat.*= # Tomcat datasource specific settings
spring.datasource.type= # Fully qualified name of the connection pool implementation to use. By default, it is auto-detected from the classpath.
spring.datasource.url= # JDBC url of the database.
spring.datasource.username= # Login user of the database.
spring.datasource.xa.data-source-class-name= # XA datasource fully qualified name.
spring.datasource.xa.properties= # Properties to pass to the XA data source.