How to remove NullPointerException from JSR 330 Spring application

383 views Asked by At

I am implementing Spring+JSF application following the guidlines of http://www.mkyong.com/jsf2/jsf-2-0-spring-integration-example/ but I am using the latest Spring version (i.e. 3.x, it already contains the JSR 330 implementation, according to the documentation, so this should not be an issue) and my own classes, that is the difference from the mentioned example.

I am stuck with NullPointerException that indicates that the bean (that acts as JSF managed) bean has not received injection of the instance of Spring bean. All the beans use JSR 330 annotations at appropriate places (@Named, @Inject) and the interfaces of the beans and the variables (under @Inject annotation) follow the usual naming patterns...

So - how to debug this situation. E.g. is there way to see all the beans that sit into the Spring application context. E.g. so we can determine that the Spring context is not initialized appropriately. Maybe there are other methods how to see what is happening in app (debug injection)?

1

There are 1 answers

0
Ravi Kadaboina On

Spring supports JSR 330 annotations for dependency injection provided you have the relevant jars in your classpath.

You need to add the following jar to your application.

<dependency>
  <groupId>javax.inject</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1</version>
</dependency>

And you might get good info by enabling logging for org.springframework

Just add log4j jar and drop in this log4j.properties file in the root of the classpath.

Log4j.properties:

log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c %M - %m\n

log4j.category.org.springframework=DEBUG

See also:

Documentation