maven模块聚合工程

2019-07-06  本文已影响0人  8奈文摩尔8
创建ssm_parent(pom)
创建子工程ssm_model(jar)
创建ssm_dao(jar)
  <!--引入jdbc.properties-->
    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    <!--配置数据源-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

    <!--配置sisees工厂-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!--
                <property name="configLocation" value="SqlMapConfig.xml"/>
        -->
    </bean>
    <!--扫描mapper-->
    <mapper:scan base-package="com.nice.dao"/>
创建ssm_service(jar)
 <!--开启包扫描-->
    <context:component-scan base-package="com.nice"/>

    <!--注册事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--配置规则-->
    <tx:advice id="adviceId" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="query*" read-only="true"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="*" read-only="false" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    <!--配置切面-->
    <aop:config>
        <!--配置切入点-->
        <aop:pointcut id="pointcutId" expression="execution(* com.nice.service.impl.*.*(..))"/>
        <aop:advisor advice-ref="adviceId" pointcut-ref="pointcutId"/>
    </aop:config>
    <!--导入dao配置文件-->
    <import resource="classpath*:applicationContext-dao.xml"/>
创建ssm_web(war)
 <!--视图解析器-->
    <bean id="resourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--忽略静态资源-->
    <mvc:default-servlet-handler/>
    <!--开启包扫描-->
    <context:component-scan base-package="com.nice.web.controller"/>
    <!--开启注册驱动-->
    <mvc:annotation-driven/>
    <import resource="classpath*:applicationContext-service.xml"/>
<!--加载springMVC-->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!--中文乱码-->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>*</url-pattern>
    </filter-mapping>
上一篇下一篇

猜你喜欢

热点阅读