SpringMVC - using a configuration file to solve the problem of hard-coded

A, db.properties 

spring dao Configuration 

<!-- 读取配置文件:数据库 -->
<context:property-placeholder location="classpath:config/db.properties" />

<!-- 配置C3P0数据源 -->
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driverClass}" />
    <property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
    <property name="user" value="${jdbc.user}" />
    <property name="password" value="${jdbc.password}" />
</bean>

db.properties

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm_steam?useUnicode=true&characterEncoding=utf-8&useSSL=true
jdbc.user=root
jdbc.password=123456

Two, log4j.properties

web.xml

<! - use the monitor to load log4j configuration file -> 
< listener > 
  < listener-class > org.springframework.web.util.Log4jConfigListener </ listener-class > 
</ listener >

log4j.properties

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

Third, custom

controller

// comment on the member variable 
@Value ( "dict.tagids $ {}" )
 Private String tagidsId; 
@Value ( "dict.platform $ {}" )
 Private String PlatformId;

dictTypeid.properties file

dict.tagids=01
dict.platform=02

springmvc.xml

<!-- springmvc配置  -->
<context:property-placeholder location="classpath:config/dictTypeid.properties" />

Guess you like

Origin www.cnblogs.com/Dm920/p/12171025.html