由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 请教一个spring的问题
相关主题
spring解决了什么问题?Java Play Framework 和 Spring 比较一下? (转载)
问个spring问题eclipse can't resolve transitive dependency projects ?
spring question一个class file dependencies 太多怎么搞?
谁能给我推荐一个strutsspringhibernate的项目Classpath questions
AOP这东西听起来很不错Maven浅淡(一)
spring frame work question@Override annotation.
关于 Java bean好虫,exploit等大牛请进--关于htmlunit
spring Annotation based configurationEclipse可以让一个项目使用refer另一个项目吗
相关话题的讨论汇总
话题: autowire话题: class话题: spring
进入Java版参与讨论
1 (共1页)
z****n
发帖数: 1933
1
定义一个接口
public interface DataAccessDao
实现
public class DataAccessDaoImpl implements DataAccessDao
单元测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/DataAccessTest.xml")
public class DataAccessTest
{
@Autowired
private DataAccessDaoImpl dataAccessDao;
spring配置

然后出错, org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type[com.phalanxim.data.dao.impl.DataAccessDaoImpl]
found for dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations: {@org.springframework
.beans.factory.annotation.Autowired(required=true)}
经过研究,在单元测试里把
private DataAccessDaoImpl dataAccessDao; 改为
private DataAccessDao dataAccessDao; 成功
或者在实现中,把
public class DataAccessDaoImpl implements DataAccessDao改为
public class DataAccessDaoImpl, 去掉接口也成功。
但是autowire="byType" 或者 autowire="byName" 都不行。
请问为什么spring autowire 倾向于匹配接口而不是class本身。我在spring配置里指
定的是
class="com.phalanxim.data.dao.impl.DataAccessDaoImpl"啊。根本没提接口。
谢谢
s******e
发帖数: 493
2
it is related to how spring proxies your class.
Google search is your best friend.
z****e
发帖数: 54598
3
autowire + qualifier
但是推荐使用
resource
z****n
发帖数: 1933
4
谢谢了,我想这篇文章说明了问题
http://blog.springsource.org/2012/05/23/understanding-proxy-usa
At startup time, a new class is created, called proxy. This one is in charge
of adding Transactional behavior as follows:

【在 s******e 的大作中提到】
: it is related to how spring proxies your class.
: Google search is your best friend.

z****n
发帖数: 1933
5
谢谢,还不熟悉这两个annotation的用法,回去好好研究。

【在 z****e 的大作中提到】
: autowire + qualifier
: 但是推荐使用
: resource

1 (共1页)
进入Java版参与讨论
相关主题
Eclipse可以让一个项目使用refer另一个项目吗AOP这东西听起来很不错
请问mvn exec怎么把pom的jar加进去?spring frame work question
j2ee without EJB关于 Java bean
What's going on with Spring IDE's website?spring Annotation based configuration
spring解决了什么问题?Java Play Framework 和 Spring 比较一下? (转载)
问个spring问题eclipse can't resolve transitive dependency projects ?
spring question一个class file dependencies 太多怎么搞?
谁能给我推荐一个strutsspringhibernate的项目Classpath questions
相关话题的讨论汇总
话题: autowire话题: class话题: spring