mavenを使ってスプリングでmybatisを集めてビジネスaspectJをオープンします.

35739 ワード

mavenを使ってスプリングでmybatisを集めてビジネスaspectJをオープンします.
  • 加入maven依存
  •   
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-contextartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-txartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-jdbcartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatisartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatis-springartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>com.github.pagehelpergroupId>
            <artifactId>pagehelperartifactId>
            <version>${version}version>
        dependency>
    
        
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-aspectsartifactId>
            <version>${version}version>
        dependency>
    
    dependencies>
    
      <build>
          <resources>
              <resource>
                  <directory>src/main/javadirectory>
                  <includes>
                      <include>**/*.propertiesinclude>
                      <include>**/*.xmlinclude>
                  includes>
                  <filtering>${version}filtering>
              resource>
          resources>
      build>
  • springプロファイル
  • を構成する.
  • appication Contect.xml
  • 	
      <context:property-placeholder location="classpath:jdbc.properties"/>
        
        <bean id="myDateSource"
         class="com.alibaba.druid.pool.DruidDataSource"
              init-method="init" destroy-method="close">
            
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
        bean>
    
        
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            
            <property name="dataSource" ref="myDateSource"/>
            <property name="configLocation" value="classpath:mybatis.xml"/>
         bean>
        
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            
            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
            <property name="basePackage" value="${dao    }"/>
        bean>
    
    
        <bean id="service" class="${}">
            <property name="${}" ref="*dao"/>
            <property name="${}" ref="*dao"/>
        bean>
        
        
        <bean id="myTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="myDateSource"/>
        bean>
        
        <tx:advice id="myAdvice" transaction-manager="myTransactionManager">
            
            <tx:attributes>
                
                <tx:method name="buy" propagation="REQUIRED" isolation="DEFAULT"
                           rollback-for="java.lang.RuntimeException"/>
                
                
                <tx:method name="add*" propagation="REQUIRES_NEW"/>
                
                <tx:method name="modify*" />
                
                <tx:method name="remove*" />
                
                <tx:method name="*" propagation="SUPPORTS" read-only="true" />
            tx:attributes>
        tx:advice>
    
        
        <aop:config>
            
            
    
            
            <aop:pointcut id="servicePt" expression="execution(* *..service..*.*(..))"/>
    
            
            <aop:advisor advice-ref="myAdvice" pointcut-ref="servicePt"/>
    
        aop:config>