ssm 配置解讀

表現層

web.xml

  • welcome-file-listcss

  • filter&filter-mappingweb

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

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

  • servlet&servlet-mappingsql

    • servlet-class:org.springframework.web.servlet.DispatcherServlet數據庫

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

springmvc.xml

  • 包掃描:session

<context:component-scan base-package="me.zhenggg.tour.controller" />
  • 開啓註解mybatis

<mvc:annotation-driven />
  • 資源視圖解析器mvc

<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>
相關文章
相關標籤/搜索