0

I am working on version upgrade of Java application,(Jdk7 to openJdk8). for that purpose, we have upgraded the spring version as per new openJdk8 in pom.xml.

I am able to build the war successfully. After deployment of war on apache-tomee-webprofile-1.7.4 (same before and after java version upgrade) I am able to login the application but not able to @Autowired the bean and hence the bean instance is null causing NullPointerException.

Application is running in Jdk7 but version upgrade (openJdk8 and Spring - 4.1.0.RELEASE) causing @Autowired not working.

Please suggest any solution for the same. We cannot move to Setter/Constructor injection as the @Autowired is used at multiple places.

>     Caused by: java.lang.NullPointerException
>        at AA.BB.CC.SearchRootLayout.MethodName(SearchRootLayout.java:100)
----------------------------------------------------------
    @Autowired
    private AdminService admin; 
    try {
        objects = admin.getObjects(Configuration.class, new String[] { "id" }, 0, 15);
     } catch (XXXXException e) { }

Interface

public interface AdminService extends ServiceBase { }

Implementation class

@Component
@Transactional
public class AdminServiceImpl extends ServiceBaseImpl implements AdminService { }

admin is null causing NullPointerException.

I forget to mention my old spring version is 3.0.5.RELEASE and now because of openJdk8 upgraded to 4.1.0.RELEASE

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Tushar
  • 1
  • 1
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – luk2302 Dec 16 '20 at 10:33
  • 1
    What's the stack trace of your exception? What code is at that line? – tgdavies Dec 16 '20 at 10:54
  • "*We cannot move to Setter/Constructor injection as the @Autowired is used at multiple places.*" This is not a valid reason why you can't do it. Change it in multiple places. It's nothing more than an excuse why you don't want to do it. – Michael Dec 16 '20 at 12:01
  • You are upgrading multiple things at once, don't. Just upgrade the JDK if you are using Spring 3.2 or higher this already runs on JDK8, no need to upgrade. If you are on a lower version, first upgrade spring (step by step) fixing issues while you go. – M. Deinum Dec 16 '20 at 12:46
  • I forget to mention my old spring version is 3.0.5.RELEASE and now because of openJdk8 upgraded to 4.1.0.RELEASE – Tushar Dec 16 '20 at 14:49
  • Upgrade to 3.2.x instead, which works with JDK8 as well (and saves you 2 versions). Also when upgrading I would strongly suggest to move to at least the lastest patch release of 3.2. – M. Deinum Dec 16 '20 at 15:01
  • That being said, without seeing the **full stacktrace** and the code that is being executed it is impossible to tell. You only posted fragments without those being clear when they are executed. – M. Deinum Dec 16 '20 at 15:05

0 Answers0