Language/frameworks : Java8/Spring 4.3.9/openjpa 2.4.3
Being a Spring newbie, I suspect I am not applying the proper pattern here.
The scenario is something like what is shown below. However, I cannot get objectB to initialize and a Null Pointer exception is thrown. I suspect that the problem is that Spring is unable to initialize class A but I cannot set the "@Component" annotation to class A as it does not have a default constructor. Is there a workaround for this scenario ? A pattern that should be followed perhaps ? This is legacy code that is being retrofitted with Spring.
@ContextConfiguration(locations = { "classpath:/context.xml" })
ClassTestA{
@Test
public void TestA(){
:
:
A a = new A ("A", "B", "C", "D");
:
:
// Following line, Throws a null pointer exception in the doSomething() method.
someobject.someMethod(a.doSomething());
}
}
class A {
@Autowired
private B objectB;
public A (string t, string m, string x, string y)
{
// variable inits
}
// C class represents a database table Entity
public C doSomething()
{
C c = new C();
c.someWork(objectB.method()); // throws a null pointer exception because obJectB is null !
}
}
@Component
public class B
{
// No constructor
}