为什么我的spring中配置bean是不允许用singleton属性 10
<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schem...
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 定义数据源bean -->
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/searchdb"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="searchService" class="com.luceneheritrixbook.searchengine.service.impl.SearchServiceImpl">
<property name="searchResultDao">
<ref local="searchResultDao"/>
</property>
</bean>
<bean id="searchResultDao" class="com.luceneheritrixbook.searchengine.service.dao.impl.SearchResultDaoImpl">
<property name="dataSource">
<ref local="myDataSource"/>
</property>
</bean>
</beans>
这是我的spring配置。两个bean中如果加入singleton="false"都会提示。bean中不允许加入singleton属性。请问为什么?? 展开
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 定义数据源bean -->
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/searchdb"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="searchService" class="com.luceneheritrixbook.searchengine.service.impl.SearchServiceImpl">
<property name="searchResultDao">
<ref local="searchResultDao"/>
</property>
</bean>
<bean id="searchResultDao" class="com.luceneheritrixbook.searchengine.service.dao.impl.SearchResultDaoImpl">
<property name="dataSource">
<ref local="myDataSource"/>
</property>
</bean>
</beans>
这是我的spring配置。两个bean中如果加入singleton="false"都会提示。bean中不允许加入singleton属性。请问为什么?? 展开
2个回答
展开全部
我给你看看源码哈,
在BeanDifinitionParserDelegate里是这样判断的,你知道原因了吧。
//singleton---现在废弃 都用scope
if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele);
}
else if (ele.hasAttribute(SCOPE_ATTRIBUTE)) {
bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询