spring 注入 切面

  • Java 声明接口定义:

public interface ShopOperatorSearchDao {  

    @DAOAction (action = DAOActionType.QUERY, method = "selectParentCategory")
    public List<Integer> selectParentCategory(@DAOParam ("shopID") int shopID);

}

    <bean id="shopOperatorSearchDAO" parent="parentDao ">
        <property name="proxyInterfaces" value="com.dianping.shop.operator.dao.ShopOperatorSearchDao "></property>
        <property name="target">
            <bean parent="Main.daoRealizeTarget ">
                <constructor-arg value="ShopSearch "></constructor-arg>
            </bean>
        </property>
    </bean>

    <bean id="parentDao " class="org.springframework.aop.framework.ProxyFactoryBean " abstract="true">
        <property name="interceptorNames">
            <list>
                <value>daoAutoRealizerAdvisor </value>
            </list>
        </property>
    </bean>

    <bean id="Main.daoRealizeTarget " class="com.dianping.avatar.dao.ibatis.IBatisGenericDaoImpl " abstract="true">
        <property name="sqlMapClient" ref="Main.sqlMapClient" />
    </bean>

    <bean id="Main.sqlMapClient" class="com.dianping.avatar.dao.ibatis.spring.LimitSqlMapClientFactoryBean">
        <property name="dataSource" ref="Main.dataSource" />
        <property name="configLocation" value="classpath:/config/sqlmap/main/sqlmap-config.xml" />
        <property name="sqlConvert" ref="mysqlConverter" />
    </bean>

    <!-- The introduce interceptor for all Dao  -->
    <bean id="daoAutoRealizer" class="com.dianping.avatar.dao.DAOAutoRealizer " />

    <!-- The advisor for inject interceptor -->
    <bean id="daoAutoRealizerAdvisor" class="org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor">
        <property name="advice" ref="daoAutoRealizer" />
        <property name="expression" value="execution(* com.dianping..dao..*.*(..)) and !execution(* com.dianping.avatar..dao..*.*(..))" />
    </bean>

  • spring的使用:注入与new

spring:最大特点就是注入。

在有spring存在的项目中,spring 的注入要统一使用,类的一步一步引用,要么为全部注入,要么都不注入。否则会出错。
比如:一个类A没有使用注入,只是用new创建了一个实例化的类B的对象。则在B类中不能使用注入。否则会出错。因为被new实例化的类和spring实例化的类是不同的,在被new实例化的对象中被注入的内容为空。

猜你喜欢

转载自reddog.iteye.com/blog/1137414
今日推荐