1

When I build and deploy my spring based Application with java version "1.8.0_112" it compiles and deploys fine.

Also, if i compile with java version "1.8.0_121", and deploy with java version "1.8.0_112" that works too.

But when I compile and deploy the same Application with java version "1.8.0_121"
it gives me an error for one service:

Error creating bean with name 'namesServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.backend.services.account.PersonService a.b.c.backend.services.serviceimpl.NamesServiceImpl.personService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CISExpressionHandler' defined in URL

[jar:file:/usr/local/tomcat7-7/webapps/ServicesApp/WEB-INF/lib/E2Services.jar!/META-INF/spring/applicationContext-security.xml]: Cannot resolve reference to bean 'CISPermissionEvaluator' while setting bean property 'permissionEvaluator'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'CISPermissionEvaluator': Requested bean is currently in creation: Is there an unresolvable circular reference?

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.backend.services.ciscase.CaseService a.b.c.backend.services.security.permissionEvaluators.CaseOwnerPermission.caseService; nested exception is org.springframework.beans.factory.BeanCreationException

One explanation, I could find was:

The exception may or may not occur depends on the creation order of beans. We load them with config something like below in web.xml (/usr/local/tomcat7-7/webapps/ServicesApp/WEB-INF/web.xml)

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
  </context-param>

The XML files will be loaded by XmlWebApplicationContext class and the loading order of files are not guaranteed. It just loads files from the file system. The problem is here. There's no problem if the class loads the application context file first, because your beans are already created when they are used for the construction injection of Spring Security. But, if it loads the Spring Security context file first, the circular reference problem occurs, because Spring tries to use your beans in the constructor injection before they had been created.

How to solve the problem?

Force the loading order of the xml files. loading the security context xml file at the end of the application context file by using

<import resource="applicationContext-security.xml">. 

Now how this got introduced with JDK version change? I don't have an explanation for that

ref: Splitting applicationContext to multiple files

Q: How do i get the order of beans at deployment ?

Community
  • 1
  • 1
kamal
  • 9,637
  • 30
  • 101
  • 168
  • this solution did not work i.e. Forcing the loading order as described above did not make the webApp come up at ALL – kamal Apr 26 '17 at 11:17
  • I compared a working Services.jar with the non-working one, and : BatchServiceImpl.java \\@Inject private WorkflowTaskService workflowTaskService; 322c324,325 < this.spResolutionService.returnCaseToSPResolution(caseId, I90SPFlagEnum.REMOVED_FROM_PENDING_STREAMLINED_PROCESSING_APPROVAL); is missing, from the non-working jar, so which jar provides @Inject ?? – kamal May 02 '17 at 14:48

0 Answers0