web项目的整体架构(spring)相关配置文件说明

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();
}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值