表现层

web.xml

  • welcome-file-list

  • filter&filter-mapping

    • filter-class:org.springframework.web.filter.CharacterEncodingFilter

    • init-param : name:encoding value:utf-8

  • servlet&servlet-mapping

    • servlet-class:org.springframework.web.servlet.DispatcherServlet

    • init-param : name:contextConfigLocation value:classpath:spring/springmvc.xml

springmvc.xml

  • 包扫描:

<context:component-scan base-package="me.zhenggg.tour.controller" />
  • 开启注解

<mvc:annotation-driven />
  • 资源视图解析器

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
  • 配置资源映射

    <mvc:resources location="/css/" mapping="/css/**"/>
    <mvc:resources location="/js/" mapping="/js/**"/>
  • 文件上传解析器

    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 设定默认编码 -->
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 设定文件上传的最大值5MB,5*1024*1024 -->
        <property name="maxUploadSize" value="5242880"/>
    </bean>
  • 引用dubbo服务

    <dubbo:application name="tour-web"/>
    <dubbo:registry protocol="zookeeper" address="192.168.73.130:2181"/>
    <dubbo:reference interface="me.zhenggg.tour.service.ItemService" id="itemService" />

服务层

web.xml

  • 加载spring容器context-param

  • listener:org.springframework.web.context.ContextLoaderListener

spring/applicationContext-*.xml

  • 加载配置文件

<context:property-placeholder location="classpath:conf/*.properties" />
  • 数据源

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        destroy-method="close">
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="maxActive" value="10" />
        <property name="minIdle" value="5" />
    </bean>
  • 让spring管理sqlsessionfactory 使用mybatis和spring整合包

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 加载mybatis的全局配置文件 -->
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
    </bean>
  • mapper扫描配置

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="me.zhenggg.tour.mapper" />
    </bean>
  • 配置包扫描器

  <context:component-scan base-package="me.zhenggg.tour.service"/>
  • 使用dubbo发布服务

    <dubbo:application name="tour-manager"/>
    <dubbo:registry protocol="zookeeper" address="192.168.73.130:2181"/>
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880"/>
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="me.zhenggg.tour.service.ItemService" ref="itemServiceImpl" timeout="600000"/>
  • 事务管理器

    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 数据源 -->
        <property name="dataSource" ref="dataSource" />
    </bean>
  • 通知&传播行为

    <!-- 通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <!-- 传播行为 -->
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="insert*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="create*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="select*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
        </tx:attributes>
    </tx:advice>
  • 切面

    <aop:config>
        <aop:advisor advice-ref="txAdvice"
            pointcut="execution(* me.zhenggg.tour.service..*.*(..))" />
    </aop:config>
  • redis单机版

    <bean id="jedisClientPool" class="me.zhenggg.tour.common.jedis.JedisClientPool">
        <property name="jedisPool" ref="jedisPool"></property>
    </bean>
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg name="host" value="192.168.73.130"/>
        <constructor-arg name="port" value="6379"/>
    </bean>
  • activemq

    <!-- 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供 -->
    <bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://192.168.73.130:61616" />
    </bean>
    <!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory -->
    <bean id="connectionFactory"
          class="org.springframework.jms.connection.SingleConnectionFactory">
        <!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->
        <property name="targetConnectionFactory" ref="targetConnectionFactory" />
    </bean>
    <!-- 配置生产者 -->
    <!-- Spring提供的JMS工具类,它可以进行消息发送、接收等 -->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->
        <property name="connectionFactory" ref="connectionFactory" />
    </bean>
    <!--这个是队列目的地,点对点的 -->
    <bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg>
            <value>spring-queue</value>
        </constructor-arg>
    </bean>
    <!--这个是主题目的地,一对多的 -->
    <bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">
        <constructor-arg value="itemAddTopic" />
    </bean>
  • 单机版solrJ

    <bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
        <constructor-arg index="0" value="http://192.168.73.130:8080/solr/collection1"/>
    </bean>

铮gg
93 声望12 粉丝