0 0

<aop:config proxy-target-class="true"/>无效,依然使用接口代理 5

<?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/mvc"
	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-3.0.xsd
	   		http://www.springframework.org/schema/context
	   		http://www.springframework.org/schema/context/spring-context-3.0.xsd
			http://www.springframework.org/schema/mvc 
			http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
			http://www.springframework.org/schema/tx  
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop          
         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	
	
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName"
			value="com.mysql.jdbc.Driver">
		</property>
		<property name="url"
			value="jdbc:mysql://127.0.0.1:3306/uunemodb">
		</property>
		<property name="username" value="root"></property>
	</bean>
	
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		
		<property name="hibernateProperties">
			<props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.jdbc.fetch_size">100</prop>
<!--                 <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop> -->
            </props>
		</property>
		
<!-- 		<property name="eventListeners"> -->
<!--             <map> -->
<!--                 <entry key="merge"> -->
<!--                     <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/> -->
<!--                 </entry> -->
<!--             </map> -->
<!--         </property> -->
		
		<property name="packagesToScan">
            <list>
                <value>com.uunemo.*</value>
            </list>
        </property>
     </bean>
	
	
	<!-- 声明一个 Hibernate 3 的事务管理器供代理类自动管理事务用 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory"><ref local="sessionFactory" /></property>
	</bean>
	
	
	 <bean id="hibernateTemplate"  class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
	<!-- 激活spring的注解. -->
	<context:annotation-config />
	
	<!-- Spring AOP auto-proxy creation (required to support Shiro annotations) -->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>

<!--  事务控制 -->
<!-- 加入shiro后报错,代理类异常,因此使用aspectj的注解方式 -->
   <tx:annotation-driven  transaction-manager="transactionManager" proxy-target-class="true"/>
<!--     <tx:annotation-driven mode="aspectj"></tx:annotation-driven>  -->
        

	<!-- 扫描注解组件并且自动的注入spring beans中. 
	例如,他会扫描@Controller 和@Service下的文件.所以确保此base-package设置正确. -->
	<context:component-scan base-package="com.uunemo" />
	<context:component-scan base-package="com.uunemo.security" />
	

	<!-- 配置注解驱动的Spring MVC Controller 的编程模型.注:次标签只在 Servlet MVC工作! -->
	<mvc:annotation-driven />
	<!-- 用注解来实现事务管理 -->

	
	<mvc:resources location="/resources/" mapping="/resources/**"/>  
	
	 <!-- =========================================================
         Shiro Components
         ========================================================= -->


    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
	<!-- Enable Shiro Annotations for Spring-configured beans. Only run after -->
	<!-- the lifecycleBeanProcessor has run: -->
	
<!-- delete on 04.26 -->	
<!-- 	<bean -->
<!-- 		class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" -->
<!-- 		depends-on="lifecycleBeanPostProcessor" /> -->
<!--     <bean -->
<!-- 		class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> -->
<!-- 		<property name="securityManager" ref="securityManager" /> -->
<!-- 	</bean> -->
	
	
	<!-- Shiro's main business-tier object for web-enabled applications (use 
		org.apache.shiro.web.mgt.DefaultWebSecurityManager instead when there is 
		no web environment) -->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<!-- Single realm app (realm configured next, below). If you have multiple 
			realms, use the 'realms' property instead. -->
		<property name="realm" ref="nemoRealm" />
		<!-- Uncomment this next property if you want heterogenous session access 
			or clusterable/distributable sessions. The default value is 'http' which 
			uses the Servlet container's HttpSession as the underlying Session implementation. 
			<property name="sessionMode" value="native"/> -->
    </bean>
    
     <!-- Define the Shiro Filter here (as a FactoryBean) instead of directly in web.xml -
         web.xml uses the DelegatingFilterProxy to access this bean.  This allows us
         to wire things with more control as well utilize nice Spring things such as
         PropertiesPlaceholderConfigurer and abstract beans or anything else we might need: -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <property name="loginUrl" value="/checkuser"/>
        <property name="successUrl" value="/home"/>
        <property name="unauthorizedUrl" value="/unauthorized"/>
        <!-- The 'filters' property is usually not necessary unless performing an override, which we
             want to do here (make authc point to a PassthruAuthenticationFilter instead of the
             default FormAuthenticationFilter: -->
<!--        <property name="filters">-->
<!--            <util:map>-->
<!--                <entry key="authc">-->
<!--                    <bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter"/>-->
<!--                </entry>-->
<!--            </util:map>-->
<!--        </property>-->
<!--        <property name="filterChainDefinitions">-->
<!--            <value>-->
<!--                /s/signup = anon-->
<!--                /s/manageUsers = perms[user:manage]-->
<!--                /s/** = authc-->
<!--            </value>-->
<!--        </property>-->
    </bean>
	
	</beans>

 spring 配置如上

 java代码如下所示: 

@Resource(name="UserDAO")
    protected UserDAO userDAO;

 报错如下:

  

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nemoRealm': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'UserDAO' must be of type [com.uunemo.daos.UserDAO], but was actually of type [$Proxy19]

 

  我已经指明了使用基于类的代理 proxy-target-class="true",为何spring还是基于代理来做,求解答

求大神解答

  

 

 

 

2013年4月28日 12:09

2个答案 按时间排序 按投票排序

0 0

孩子。。。spring 在生产代理类的时候。。会根据原生类来判断是使用jdk的动态代理还是cglib来生成。及时你写了
<aop:aspectj-autoproxy expose-proxy="true"/>
还有个问题。。。。和版本有点问题。。。你用的spring多少版本的?

2013年4月28日 14:27
0 0

Bean named 'UserDAO' must be of type [com.uunemo.daos.UserDAO], but was actually of type [$Proxy19] 

我看下你的UserDAO咋实现的

可以使用 如下判断下是么代理
AopUtils.isAopProxy()
AopUtils.isCglibProxy() //cglib
AopUtils.isJdkDynamicProxy() //jdk动态代理



1、
使用<aop:aspectj-autoproxy expose-proxy="true"/> 替换
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
        <property name="proxyTargetClass" value="true"/>
    </bean>

2013年4月28日 13:02

相关推荐

    Maven拆分代码.zip

    &lt;!--配置连接池--&gt; &lt;bean id="dataSource" class=... &lt;aop:config&gt; &lt;aop:pointcut id="pointcut" expression="execution(* com.itheima.service.impl.*.*(..))"/&gt; &lt;aop:advisor advice-ref="advice" pointcut-ref=

    struts2.3+hibernate3.6+spring3.1整合的纯xml配置的小项目

    &lt;context:annotation-config&gt;&lt;/context:annotation-config&gt; &lt;context:component-scan base-package="org.whvcse"&gt;&lt;/context:component-scan&gt; &lt;tx:annotation-driven transaction-manager="txManager" /&gt; &lt;!-- ...

    springmvcmybatis

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="location" value="classpath:jdbc.properties" /&gt; &lt;/bean&gt; &lt;!-- &lt;bean id="dataSource" class="org....

    spring applicationContext 配置文件

    &lt;value&gt;true&lt;/value&gt; &lt;/constructor-arg&gt; &lt;/bean&gt; &lt;!-- ptc windchill的數據庫 --&gt; &lt;bean id="dataSourcePdm" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt; &lt;property ...

    springmvc-ibatis

    &lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"&gt; &lt;property name="locations"&gt; &lt;value&gt;classpath:jdbc.properties&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- 配置數...

    SpringMVC+Hibernate全注解整合

    &lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"&gt; &lt;property name="locations"&gt; &lt;value&gt;classpath:properties/jdbc.properties&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; ...

    spring3.2+strut2+hibernate4

    &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="locations"&gt; &lt;list&gt; &lt;value&gt;classpath*:jdbc.properties&lt;/value&gt; ...

    JTA事务源码示例

    &lt;aop:config&gt; &lt;aop:pointcut id="serviceOperation" expression="execution(* *..servi1ce*..*(..))"/&gt; &lt;aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/&gt; &lt;/aop:config&gt; &lt;!-- 通知配置...

    基于java的企业级应用开发:AspectJ开发.ppt

    基于XML的声明式AspectJ &lt;aop:config&gt;元素及其子元素如下: 小提示:图中灰色部分标注的元素即为常用的配置元素 XML文件中常用元素的配置方式如下: 基于XML的声明式AspectJ &lt;bean id="myAspect" class=...

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    &lt;aop:config proxy-target-class="true"/&gt; &lt;tx:annotation-driven transaction-manager="txManager"/&gt; &lt;!-- 采用单数据源事务控制方式,通过注解来定义事务--&gt; &lt;bean id="txManager" class="org.spring...

    spring框架手动提交事务,jdbctample

    &lt;aop:aspectj-autoproxy proxy-target-class="true"&gt;&lt;/aop:aspectj-autoproxy&gt; xml中要有这句,可以解决子类类报错的问题。 或者去掉这句话,同时去掉public class AccountServiceImpl implements AccountService {...

    ssh框架在application.xml中配置数据源所需jar

    &lt;prop key="show_sql"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="mappingResources"&gt; &lt;list&gt; &lt;value&gt;com/longxian/drp/models/Module.hbm.xml&lt;/value&gt; &lt;value&gt;...

    SSH第7章上机.zip ACCP8.0

    &lt;/aop:config&gt; spring和struts2的整合 加入整合包 加入struts的必须包 struts整合spring的包 struts2-spring-plugin-2.3.15.3.jar spring整合struts的包 org.springframework.web-3.1.3.RELEASE.jar org.spring...

    三大框架下分页源代码

    &lt;tx:method name="*" read-only="true"/&gt; &lt;/tx:attributes&gt; &lt;/tx:advice&gt; //tx标签代表时间传播 &lt;aop:config&gt;//切入 &lt;aop:pointcut id="allServiceMethod" expression="execution(* com.cstp.service.*.*...

    Spring AOP配置源码

    &lt;/beans&gt;&lt;context:annotation-config/&gt; &lt;context:component-scan base-package="com.spring.*"/&gt; 两行为开启spring的注解配置 &lt;aop:aspect id="aspect" ref="logIntercepter"&gt; 引入具体的AOP操作类 &lt;aop:pointcut ...

    SpringMVC-SSH全注解

    &lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"&gt; &lt;property name="locations"&gt; &lt;value&gt;classpath:jdbc.properties&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- 配置數...

    springjdbc

    &lt;property name="defaultAutoCommit" value="true" /&gt; &lt;/bean&gt; &lt;!-- jdbc注入 --&gt; &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt; &lt;property name="dataSource" ref=...

    Spring AOP demo

    &lt;aop:config&gt; &lt;!-- 配置切点表达式 --&gt; &lt;aop:pointcut id="pointcut1" expression="execution(public void com.jas.aop.bean.PersonImpl.sayHello())"/&gt; &lt;aop:pointcut id="pointcut2" expression=...

    spring-xmemcached

    &lt;bean id="cacheProxyFactoryBean" class="org.springframework.aop.framework.ProxyFactoryBean"&gt; &lt;property name="interceptorNames"&gt; &lt;list&gt; &lt;value&gt;cacheBeforeAdvice&lt;/value&gt; &lt;value&gt;cacheAfterAdvice&lt;/...

Global site tag (gtag.js) - Google Analytics