Spring注入失败,但是getBean();却可以使用

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
">



class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">






org.hibernate.dialect.PostgreSQLDialect
true
true
update



class="org.springframework.orm.hibernate4.HibernateTransactionManager">

<!-- 依赖注入上面定义的sessionFactory -->




class="org.springframework.transaction.interceptor.TransactionInterceptor">

<!-- 依赖注入上面定义的事务管理器transactionManager -->



<!-- 定义需要进行事务拦截的方法及所采用的事务控制类型 -->





<!-- 以browse、list、load、get及is开头的所有方法采用只读型事务控制类型 -->

PROPAGATION_REQUIRED,readOnly

PROPAGATION_REQUIRED,readOnly

PROPAGATION_REQUIRED,readOnly

PROPAGATION_REQUIRED,readOnly

PROPAGATION_REQUIRED,readOnly

<!-- 所有方法均进行事务控制,如果当前没有事务,则新建一个事务 -->

PROPAGATION_REQUIRED






<!-- 定义BeanNameAutoProxyCreatorf进行Spring的事务处理 -->

class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

<!-- 针对指定的bean自动生成业务代理 -->





HibernateManDao

LoginResource





<!-- 这个属性为true时,表示被代理的是目标类本身而不是目标类的接口 -->



true



<!-- 依赖注入上面定义的事务拦截器transactionInterceptor -->





transactionInterceptor







<!-- -->









<!-- -->

在java类里面必须有set方法,同时注意命名规范

1、缺少jar包2、未扫描导3、注入时注意命名规范,比如@Autowired按byType自动注入,而@Resource默认按 byName自动注入