在Spring中,依赖注入的Bean对象为null

时间:2017-11-19 09:05:49

标签: java spring spring-mvc

我正在我的impl类中自动装配一个dao类

@WebService
public class TransactionImpl implements Transaction{        

@Autowired
BBDao dao;

}

BBDao界面如下

public interface BBDao { /* Methods in it */ }

实现BBDao接口的实现类是

public class BBDaoImpl extends JdbcDaoSupport implements BBDao {    

@Autowired
ServletContext ctx; 

@Autowired
DataSource dataSource;

// Methods overriding here 

}

在web.xml中定义的Servlet

<servlet>
    <servlet-name>spring-web</servlet-name>
    <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring-web</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

最后spring-web-servlet.xml是

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd">


<context:property-placeholder location="classpath:datasource-cfg.properties" />


<bean id="bbDAO" class="net.bb.dao.BBDaoImpl">
    <property name="dataSource" ref="dataSource" />
</bean> 

<!-- AS400 Data source Bean -->
<bean id="dataSource"
     class="org.springframework.jdbc.datasource.DriverManagerDataSource">

    <property name="driverClassName" value="com.ibm.as400.access.AS400JDBCDriver" />
    <property name="url" value="${as400.url}" />
    <property name="username" value="${as400.username}" />
    <property name="password" value="${as400.password}" />
</bean>

<mvc:annotation-driven />

</beans>

BBDao bean对象将为null。

我的配置有错吗?任何建议都将不胜感激。

0 个答案:

没有答案