I am working on a Spring-MVC application in which I am autowiring a field, but it is getting set as NULL. I checked the solutions on net for the same problem, as they describe, I should not create a new instance of classes when working, rather get it from spring. I tried that as well, but it always complains the resource is not found.
Here is the class :
@Service
@Transactional
public class GoogleAuthorization{
@Autowired
private DriveQuickstart driveQuickstart; // This guy is null
public void saveCredentials(final String authCode) throws IOException {
GoogleTokenResponse response = flow.newTokenRequest(authCode).setRedirectUri(CALLBACK_URI).execute();
Credential credential = flow.createAndStoreCredential(response, null);
System.out.println(" Credential access token is "+credential.getAccessToken());
System.out.println("Credential refresh token is "+credential.getRefreshToken());
// It fails at below point.
this.driveQuickstart.storeCredentials(credential);
}
Controller code :
@RequestMapping(value = "/getgooglelogin")
public String getGoogleLogin(HttpServletRequest request, HttpServletResponse response, HttpSession session,Model model) {
/* ApplicationContext applicationContext = new ClassPathXmlApplicationContext("../WEB-INF/spring/root-context.xml");
GoogleAuthorization helper = (GoogleAuthorization) applicationContext.getBean("helper");*/
GoogleAuthorization helper = new GoogleAuthorization();
}
I tried getting it via the root-context.xml as you can see above, but no matter what path I would put, it could not find it.
DriveQuickStartImpl :
@Service
@Transactional
public class DriveQuickstartImpl implements DriveQuickstart{
// All these below guys work just fine.
@Autowired
private PersonService personService;
@Autowired
private GoogleDriveService googleDriveService;
@Autowired
private GroupAttachmentsService groupAttachmentsService;
@Autowired
private GroupAccountService groupAccountService;
}
What am I doing wrong. Any help would be nice. Thanks a lot.
Update
Image for where root-context.xml belongs :