有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java只读事务在我的AOP配置中不起作用

我试图学习如何使用AOP,我试图在Spring的应用程序上下文中设置一个只读事务,但它不起作用,它仍然将数据提交到数据库

我真的不知道我做错了什么,如果你能帮我,我会很高兴的

applicationcontext。xml

<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx=     "http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/tx`enter code here`
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<aop:aspectj-autoproxy proxy-target-class="true" />

<!--advice-->
    <tx:advice  id="txAdvice" transaction-manager="txManager">
       <tx:attributes>            
            <tx:method name="eliminar*" read-only="true"  />
        </tx:attributes>
    </tx:advice>

<!-- Aspect -->
    <bean id="Aop" class="com.all.mymavenii.dao.TiposSolicitudDAO"  />
    <aop:config>
        <aop:pointcut id="point" 
                      expression="execution(* com.all.mymavenii.dao.TiposSolicitudDAO.eliminar(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="point"/>
    </aop:config>

<!-- Data Base configuration  -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="/WEB-INF/config/basedatos/jdbc.properties" />
    </bean>

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${sifa.jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${sifa.jdbc.url}" />
        <property name="user" value="${sifa.jdbc.username}" />
        <property name="password" value="${sifa.jdbc.password}" />
        <property name="acquireIncrement" value="${sifa.c3p0.acquireIncrement}" />
        <property name="minPoolSize" value="${sifa.c3p0.minPoolSize}" />
        <property name="maxPoolSize" value="${sifa.c3p0.maxPoolSize}" />
        <property name="maxIdleTime" value="${sifa.c3p0.maxIdleTime}" />
    </bean>

    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <context:component-scan base-package="com.all.mymavenii.servicio">
        <context:include-filter expression="org.springframework.stereotype.Service" type="annotation" />
    </context:component-scan>

    <context:component-scan base-package="com.all.mymavenii.dao">
        <context:include-filter expression="org.springframework.stereotype.Repository"    type="annotation" />
    </context:component-scan>

</beans>

IndexController

执行方法的请求的代码:

@Controller
@RequestMapping("/")
public class IndexControlador {

    @Autowired
    private Servicio service;
/*
. . .
*/
   @RequestMapping(value = "/vista2", method = RequestMethod.POST)
    public String tipoSolicitudEliminar(@RequestParam("clv") String claveTipo) {
        service.eliminar(claveTipo);
        return "redirect:/vista2";
    }      
}

服务

@Service
public class Servicio {
    @Autowired 
    private TiposSolicitudDAO tiposSolicitudDAO;

    public void eliminar(String clave)
    {
        tiposSolicitudDAO.eliminar(clave);        
    }
}

DAO

@Repository("tiposSolicitudDAO")
public class TiposSolicitudDAO {

    private JdbcTemplate jdbcTemplate;
    private final String DELETE_SQL;

    @Autowired
    public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public TiposSolicitudDAO() {
        this.DELETE_SQL = "DELETE FROM sifa_tipos_solicitud WHERE  tiso_clave =? ";
    }

 public void eliminar(String claveTiposSolicitud) {
        jdbcTemplate.update(DELETE_SQL, new Object[]{claveTiposSolicitud});
    }
}

依赖关系

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>4.0.5.RELEASE</version>
</dependency>        
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.8.1</version>
</dependency>        
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.8.1</version>
</dependency>

共 (0) 个答案