spring 注解不生效的问题
本菜鸟试着用spring的注解方式,但是注解不生效。
web.xml文件片段:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- Data Source-->
<bean id="dataSource" 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/helloWorld?createDatabaseIfNotExist=true" />
<property name="username" value="root" />
<property name="password" value="root" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="10" />
<property name="maxWait" value="5000" />
</bean>
<!--sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean ">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
<context:annotation-config />
<!--bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/-->
<bean id="fruitService" class="com.megasoft.service.impl.FruitServiceImpl"/>
<bean id="fruitService_2" class="com.megasoft.service.impl.FruitService_2Impl"/>
</beans>
java代码如下:
@Resource
private IFruitService_2 fruitService_2;
public void test() {
fruitService_2.hello();
}
导入的包如下:
晕不懂发图;
最后在
public void test() {
fruitService_2.hello();
}
抛出了空指针。