SOAP 웹 서비스를위한 새 프로젝트를 빌드하고 있습니다. 이전에는 연결을 열고 닫는 데 JDBC 레이어를 사용했습니다. 이제 JDBC 템플릿으로 Spring으로 변환하고 있습니다. 모든 레이어를 구성하고 구성 요소에 주석을 달았습니다. 내 서비스 IMPL 클래스의 DAO 빈을 사용하려고하면, 그것은스프링에서 Autowired 객체에 대한 널 포인터 예외가 발생했습니다.
public interface BBDao { /* Methods in it */ }
구현을 다음과 같이
@Component
@WebService
public class TransactionImpl implements Transaction{
@Autowired
BBDao dao; --> This is coming as null when I use it in the method
}
BBDao 인터페이스는 널 포인터 예외
@Service
@WebService
public interface Transaction { // Web methods here for SOAP Web service
}
IMPL 클래스 나에게 던졌습니다 BBDao 인터페이스를 구현하는 클래스는
public class BBDaoImpl extends JdbcDaoSupport implements BBDao {
@Autowired
ServletContext ctx;
@Autowired
DataSource dataSource;
// Methods overriding here
}
0입니다.
서블릿은 web.xml을
<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>
에 정의와 BBDao 빈 객체가 null로오고있다
<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:component-scan base-package="com.bb.controller,com.bb.dao,com.bb.service" />
<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>
마지막으로 스프링 웹-servlet.xml 파일입니다.
구성에 어떤 실수가 있습니까? 모든 조언을 크게 주시면 감사하겠습니다.
P.S : 게시물의 대부분은 구성 요소 검사에 대해 얘기로 내가뿐만 아니라 다른 게시물을 따라하고 패키지가 올바른지
우리는 인터페이스의 인스턴스를 생성 어차피 우리가 구현하지 않고 인터페이스를 autowire하기 어차피
는 스프링 빈은 BBDaoImpl입니다 @ConditionalOnMissingBean (BBDao.class) 같은 this
사용자 주석을 참조? 이 클래스에서 당신은'@ Component' 또는'@Service'를 가지고 있습니까? – pvpkiran
아니야, 거기없는 키란. @Component를 추가하고 테스트했습니다. 여전히 동일 – Yakhoob
Kiran, 방금 일부 테스트 컨트롤러를 사용하여 테스트했을 때 발견되었습니다. dao는 null이 아닙니다. 하지만 SOAPUI 도구를 사용하면 null이됩니다. – Yakhoob