Sheetal Jain
Sheetal Jain

Reputation: 105

java.lang.NullPointerException in spring integration

I am new to Spring Integration framework and just trying to implement a basic example but getting a null pointer exception.

integration-spring.xml

 <int:gateway service-interface="com.fil.MyService" default-request-
 channel="in"/> 
 <int:chain input-channel="in">
   <int:transformer expression="'hello:'+payload"></int:transformer>
   <int:service-activator>
       <int-groovy:script>
           <![CDATA[println "processing"+payload]]>
       </int-groovy:script>
       </int:service-activator>
    </int:chain>
  </beans>

MyService.java

public interface MyService {
void single(String foo);
}

Test.java

@ContextConfiguration(locations = { "/WEB-INF/integration-spring.xml" })
 public class MyServiceTest {

@Autowired
private MyService service; 

@Test
public void test() {
    try{
        service.single("hELLO ");//Getting null pointer exception
    }
    catch(Exception e){
        e.printStackTrace();
    }
}}

Upvotes: 0

Views: 857

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

You also need @Runwith(SpringJunit4ClassRunner.class) on your test class so the test framework loads your application context and autowires the test class.

Upvotes: 1

Related Questions