@Repository("aadaoimpl")
public class aaimpl extends HibernateDaoSupport implements aadao
这是dao层的
@Service("aaservice")
public class aasrviceimpl implements aaservice
@Resource(name="aadaoimpl")
private aadao a;
这是Service层的
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<context:component-scan base-package="com"></context:component-scan>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/java/pojo/aa.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源
dataSource在applicationContext-dao.xml中配置了
-->
<property name="dataSource" ref="dataSource"/>
tx:attributes
<!-- 传播行为 -->
/tx:attributes
/tx:advice
这是我的spring配置文件信息
@Test
public void testShow() {
ApplicationContext ap=new ClassPathXmlApplicationContext("applicationContext.xml");
aaservice as=(aaservice) ap.getBean("aaservice");
aa ad=new aa();
ad.setName("as");
ad.setSex("f");
as.savea(ad);
}
最后就是我的测试信息
我用普通spring的方式注入就很好 但是换注解就报
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aadaoimpl' defined in file