1、web.xml
web.xml文件是用来配置:欢迎页、servlet、filter等的。当你的web工程没用到这些时,你可以不用web.xml文件来配置你的web工程。
2、applicationContext.xml
spring的配置文件
<!-- 加载配置文件:applicationContext.properties [BEGIN] -->
<context:property-placeholder ignore-unresolvable="true" ignore-resource-not-found="true"
location="classpath*:/config/applicationContext.properties"/>
<!-- 加载配置文件:applicationContext.properties [END] -->
<!-- 开启注解扫描功能,同时过滤@Controller注解 [BEGIN] -->
<context:component-scan base-package="com.jinhetech.paprika">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
<!-- 开启注解扫描功能,同时过滤@Controller注解 [BEGIN] -->
<!-- 配置DataSource [BEGIN] -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxPoolSize" value="${jdbc.pool.maxPoolSize}"/>
<property name="minPoolSize" value="${jdbc.pool.minPoolSize}"/>
<property name="initialPoolSize" value="${jdbc.pool.initialPoolSize}"/>
<!-- 设置最大空闲时间,若在设置的时间内未使用,则连接被丢弃,若为0,则永不丢弃 -->
<property name="maxIdleTime" value="${jdbc.pool.maxIdleTime}"/>
</bean>
3 springmvc的配置文件
spring-servlet这个名字是因为上面web.xml中<servlet-name>标签配的值为spring(<servlet-name>spring</servlet-name>),再加上“-servlet”后缀而形成的spring-servlet.xml文件名,如果改为springMVC,对应的文件名则为springMVC-servlet.xml。
springmvc-servlet.xml
<!-- 启用spring mvc 注解 -->
<context:annotation-config />
<!-- 设置使用注解的类所在的jar包 -->
<context:component-scan base-package="controller"></context:component-scan>
<!-- 完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/jsp/" p:suffix=".jsp" />
4 properties文件
常量文件
通常通过代码加载到项目中使用
private static Properties properties = new Properties();
static {
try {
// 加载properties文件
properties.load(Constants.class.getClassLoader().getResourceAsStream("applicationContext.properties"));
CLASSIFY_MAP.put("cr", CLASSIFY_ENTITY_CROP);
CLASSIFY_MAP.put("re", CLASSIFY_ENTITY_REGION);
} catch (Exception e) {
e.printStackTrace();
}
}