Database data source configuration in the Applicationcontext.xml configuration file in spring

Source: Internet
Author: User
"0" Preface: J AVA Web Development Regardless of the framework is inseparable from the various XML configuration, spring configuration file is used to guide the spring factory bean production, Dependency injection (assembly) and Bean instance distribution "sheets." Java EE programmers must learn and flexibly apply this "drawing" to accurately express their "production intentions". The spring configuration file is one or more standard XML documents, and Applicationcontext.xml is the default profile for spring, and will attempt to load the default configuration file when the container is started without the specified configuration document.        This article focuses on database data source configuration. "1" Effect: With ApplicationContext, you can let the system load your bean (for example, when the servlet container initializes Contextloaderservlet, the Contextloader class loads the spring Framework), rather than using encoding to load. The ApplicationContext interface is the foundation of the context package and is located in the Org.springframework.context package, providing all the functionality of the beanfactory. In addition, ApplicationContext provides the following features to support the framework's working methods:
A.messagesource, provides the internationalization support of language information
B. Providing access support for resources such as URLs and file systems
C. Event propagation support for beans that implement the Applicationlistener interface
D. provide different contexts for different application environments, such as the Xmlwebapplicationcontext class "2" data source configuration that supports Web applications:

<!--header file, focus on encoding--<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" > <beans >

<!--Create a data source-- [HTML] view plain copy print? <bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" >

<!--database driver, I'm using MySQL database---
[HTML] view plain copy print? <propertyname propertyname= "Driverclassname" > <value>com.mysql.jdbc.Driver</value> </prope Rty>

<!--database address, here also pay attention to coding, otherwise garbled but very depressed oh. -
[HTML] view plain copy print? <property name= "url" > <value> jdbc:mysql://localhost:3306/tie?useunicode=true&characterencod Ing=utf-8 </value> </property>

<!--database user name--
[HTML] view plain copy print? <property name= "username" > <value>root</value> </property>

<!--database Password-- [HTML] view plain copy print? <property name= "Password" > <value>123</value>

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.