#spring autowired Null pointer exception on service

13 messages · Page 1 of 1 (latest)

versed forge
#

when I debug my test, I cant call my method inside my service because null pointer exception on this picture attached.

@UtilityClass
@Slf4j
public class DppNptePrivilegeUtil {

  @Autowired
  private UserProfileIndividualData userProfileIndividualData;
@Slf4j
@Service
public class UserProfileIndividualData extends UserProfileClientService {
java.lang.NullPointerException
    at com.netcompany.dpp.security.auth.server.util.DppNptePrivilegeUtil.testAddNumbersDPP

How do i fix this?

cosmic prismBOT
#

This post has been reserved for your question.

Hey @versed forge! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

ionic tangle
#

What does your test class look like

versed forge
#



class OAuth2UtilsSpec extends Specification {

void 'AAAAAAAAAAA'() {
    given:

    when:
    OAuth2Utils.test1234(1,1)

    then:

    def e = 5 + 5
  }
}
ionic tangle
#

So @Autowired requires there to be a Spring Context running in order to inject that dependency. If you're running your tests without this context it's not going to do the dependency injection and you'll end up with the null value

#

One way to get an application context running in test env is

    private final ApplicationContextRunner contextRunner
            = new ApplicationContextRunner();

You can get a bean with all the autowirings with

contextRunner.getBean(YourClass.class)
versed forge
#

I'm sorry thats Chinese to me

#

I don't understand why its needed to do that

#

there are many other tests in this project which are running tests on services

versed forge
ionic tangle
versed forge
#

That just doesnt mean anything to me but thankyou for your time