Spring Terminator-use spring Web ApplicationsProgramConfigure and integrate all parts (databases)
1. Add spring's dispatch servlet to Web. xml
<Servlet> <br/> <servlet-Name> controller </servlet-Name> <br/> <servlet-class> Org. springframework. web. servlet. dispatcherservlet </servlet-class> <br/> <init-param> <br/> <param-Name> contextconfiglocation </param-Name> <br/> <param-Value> <br/> <! -- Note the file name --> <br/>/WEB-INF/controller-servlet.xml <br/> </param-value> <br/> </init-param> <br/> <load- on-startup> 1 </load-on-startup> <br/> </servlet>
2. Add the bean configuration file of spring. Note that the configuration file name must be in the following format: [servlet-name]-servlet. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! Doctype beans public "-// spring // DTD bean // en" "http://www.springframework.org/dtd/spring-beans.dtd"> <br/> <beans> <br/> <bean id = "propertyconfigurer" <br /> class = "org. springframework. beans. factory. config. propertyplaceholderconfigurer "> <br/> <property name =" locations "> <br/> <list> <br/> <value> WEB-INF/classes/datasource. properties </value> <br/> </List> <br/> </property> <br/> </bean> <br/> <bean id = "datas Ource "<br/> class =" org. apache. commons. DBCP. basicdatasource "<br/> destroy-method =" close "> <br/> <property name =" driverclassname "> <br/> <value >$ {database. driverclassname} </value> <br/> </property> <br/> <property name = "url"> <br/> <value >$ {database. URL} </value> <br/> </property> <br/> <property name = "username"> <br/> <value >$ {database. username} </value> <br/> </property> <br/> <property name = "password"> <br/> <Value >$ {database. password }</value> <br/> </property> <br/> <property name = "maxactive"> <br/> <value >$ {database. pool. maxactive} </value> <br/> </property> <br/> <property name = "maxwait"> <br/> <value >$ {database. pool. maxwait} </value> <br/> </property> <br/> <property name = "maxidle"> <br/> <value >$ {database. pool. maxidle} </value> <br/> </property> <br/> </bean> <br/> <bean id = "viewresolver" <br/> class =" org. spring Framework. web. servlet. view. internalresourceviewresolver "> <br/> <property name =" viewclass "> <br/> <value> Org. springframework. web. servlet. view. jstlview </value> <br/> </property> <br/> <property name = "prefix"> <br/> <value>/</value> <br/> </property> <br/> <property name = "suffix"> <br/> <value>. JSP </value> <br/> </property> <br/> </bean> <br/> <bean id = "handlermapping" <br/> class = "org. springframework. web. servl ET. handler. beannameurlhandlermapping "/> <br/> <bean id =" methodnameresolver "<br/> class =" org. springframework. web. servlet. MVC. multiaction. parametermethodnameresolver "> <br/> <property name =" paramname "> <br/> <value> method </value> <br/> </property> <br/> <property name = "defaultmethodname"> <br/> <value> execute </value> <br/> </property> <br/> </bean> <br/> <! -- Definition of other beans --> <br/> </beans>
3. Configure the database and add the datasource. properties configuration file (in SRC)
Database. url = <br/> database. driverclassname = com. mySQL. JDBC. driver <br/> database. username = <br/> database. password = <br/> database. pool. maxactive = 20 <br/> database. pool. maxwait = 5000 <br/> database. pool. maxidle = 10
4. Add the log4j configuration file
Log4j. rootlogger = debug, file, console <br/> log4j. appender. console = org. apache. log4j. leleappender <br/> log4j. appender. console. threshold = debug <br/> log4j. appender. console. layout = org. apache. log4j. patternlayout <br/> log4j. appender. console. layout. conversionpattern = [% d] % 5 p [% c {1 }:% m]-% m % n <br/> log4j. appender. file = org. apache. log4j. dailyrollingfileappender <br/> log4j. appender. file. file = D:/reip. log <br/> log4j. appender. file. layout = org. apache. log4j. patternlayout <br/> log4j. appender. file. layout. conversionpattern = [% d] % 5 p [% c {1} \: % m]-% m % N