0

I'm building a new project for SOAP web services. Earlier I was using JDBC layer for opening and closing connections. Now, I'm converting it into Spring with JDBC template. I've configured all the layers and annotated the components. When I try to use the dao bean in my service impl class, it throws me null pointer exceptions

@Service
@WebService
public interface Transaction { // Web methods here for SOAP Web service
}

Impl class

@Component
@WebService
public class TransactionImpl implements Transaction{        

    @Autowired
    BBDao dao;  --> This is coming as null when I use it in the method

}

BBDao interface is as follows

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

The implementation class which is implementing BBDao interface is

public class BBDaoImpl extends JdbcDaoSupport implements BBDao {    

@Autowired
ServletContext ctx; 

@Autowired
DataSource dataSource;

// Methods overriding here 

}

Servlet defined in 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>

And finally the spring-web-servlet.xml is

<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>

The BBDao bean object is coming as null.

Is there any mistake in my configuration? Any advice would be greatly appreciated.

P.S : I have followed other posts as well, as most of the posts talk about component scan only and the packages are correct

3
  • is BBDaoImpl a spring bean? I mean do you have @Component or @Service on this class ? Commented Nov 19, 2017 at 10:39
  • No Kiran its not there. I added @Component now and tested. Still the same Commented Nov 19, 2017 at 10:41
  • Kiran, I just found when I test it using a some test controller, dao is not null. but when I try using SOAPUI tool, it gives null. Commented Nov 19, 2017 at 10:58

1 Answer 1

1

We cant autowire an interface without Implementation as we cant create instance for interface. But you can try the ones below and see if it works.

Few things what you could do.

Add to your spring-webservlet.xml

And also refer this

user annotation like @ConditionalOnMissingBean(BBDao.class)

Sign up to request clarification or add additional context in comments.

1 Comment

the dao object is having the values when I call one of the impl method from a test controller. Now when I call a method from SOAP UI to one of the method in Impl class, then it gives null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.