java抽象类是无法实例化的,而spring注入得实例化类对象,所以,不用想实例话抽象类了。想法:publicabstractclassBasicServiceimplementsBasicServiceInter{privateSessionFactorysessionFactory;}publicclassEmployeeServiceextendsBasicServiceimplementsEmployeeServiceInter{}由上可看出EmployeeService继承了抽象类BasicService在applicationContext.xml文件中配置beanid=basicServiceclass=com.basic.BasicServicepropertyname=sessionFactoryref=sessionFactory//beanbeanid=employeeServiceclass=com.service.imp.EmployeeService/bean然后EmployeeService就可以使用sessionFactory了?显然不是在文章的开头把原因说了;上面applicationContext.xml这样配是会报错了但是怎么让EmployeeService使用sessionFactory?下面有两个解决方案一(比较麻烦)直接(不能配basicService因为抽象类无法实例化)beanid=employeeServiceclass=com.service.imp.EmployeeServicepropertyname=sessionFactoryref=sessionFactory//bean缺点每个继承basicService类在要使用sessionFactor的话都要在applicationContext.xml都要多配下面这一句话propertyname=sessionFactoryref=sessionFactory/二(简单)@TransactionalpublicabstractclassBasicServiceimplementsBasicServiceInter{@ResourceprivateSessionFactorysessionFactory;}使用标注方法配