Spring MVC reads the configuration content of. properties through the @ Value annotation, @ value. properties
Step 1:
Configure in applicationContext. xml:
1 <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 2 <property name="locations"> 3 <list> 4 <value>classpath:/config/*.properties</value> 5 </list> 6 </property> 7 </bean> 8 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> 9 <property name="properties" ref="configProperties" />10 </bean>
Step 2:
Create a configuration file:
Example: userPageSize = 5
Step 3:
Use annotations in the Controller to obtain the configuration item content:
1 @Value("#{configProperties['userPageSize']}")2 private String userPageSize;
Step 4:
The following code can use the private variable userPageSize. The value of this string is 5 configured in the configuration file.
How does eclipse build springmvc + mybatis?
SpringMVC + MyBatis + Freemarker simple framework (1)
I. Development Environment:
For details about Eclipse, Tomcat, and SVN, see the following post.
Www.iteye.com/topic/982182
Install svn and maven plug-ins:
1. Install the gef plug-in first
Address: download.eclipse.org/tools/gef/updates/interim/
2. Install the svn plug-in
Address: subclipse.tigris.org/update_1.6.x
3. maven plug-in
M2eclipse-core Update address: m2eclipse.sonatype.org/sites/m2e
M2eclipse-extras Update City: m2eclipse.sonatype.org/sites/m2e-extras
4. Possible Installation Problems
If you directly install maven2 online, the dependency plug-in cannot be found and cannot be installed. You must install the gef plug-in before installing the m2eclipse-core plug-in. However, installing the m2eclipse-extras plug-in depends on the subclipse plug-in. Therefore, the correct installation sequence of the three plug-ins is: gef plug-ins, subclipse plug-ins, and m2eclipse plug-ins.
Ii. web. xml and applicationContext. xml configuration
1. web. xml file Configuration:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app xmlns: xsi = "www.w3.org/2001/XMLSchema-instance"
Xmlns = "... the remaining full text>
How does spring mvc + hibernate4 read the configuration file and obtain the original name of the JNDI data?
1. Create a configuration file: jdbc. properties
Db. driver = oracle. jdbc. driver. OracleDriver
Db. url = jdbc: oracle: thin: @ 10.100.15.66: 1521: cdgk
Db. user = shbx_sn
Db. password = shbx_sn
Db. alias = OrclPool
Db. houseKeepingTestSql = select sysdate from dual
Db. characterEncoding = GBK
Db. maximumConnectionCount = 6
Db. minimumConnectionCount = 1
Db. maximumActiveTime = 19999999
Db. jndiName = jbzh_sn
2. Configure spring mvc
<Bean id = "propertyConfigurer" class = "org. jasypt. spring. properties. EncryptablePropertyPlaceholderConfigurer">
<Constructor-arg ref = "configurationEncryptor"/>
<Property name = "location">
<! -- Introduce the configuration file here -->
<Value> classpath: jdbc. properties </value>
</Property>
</Bean>
<! -- Use the connection pool to shield the 'jndi source'. Use the JNDI data source to shield the connection pool. At the same time, you must create a jbzh_sn data source in weblogic -->
<! -- 1. proxool connection pool -->
<Bean id = "dataSource" class = "org. logicalcobwebs. proxool. ProxoolDataSource">
<! -- Use properties in the configuration file here -->
<Property name = "driver" value = "$ {db. driver}"/>
<Property name = "driverUrl" value = "$ {db. url}"/>
<Property name = "user" value = "$ {db. user}"/>
<Property name = "password" value = "$ {db. password}"/>
<Property name = "alias" value = "$ {db. alias}"/>
<Property name = & quo ...... remaining full text>