Announcement Announcement Module
Collapse
No announcement yet.
Autowired Service get NullPointerException. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowired Service get NullPointerException.

    Hi All,

    Does anyone know how to call a service in Spring context by tablib from JSP page?
    When I used @Autowired to get service. the service has NullPointerException error.
    It seem that it cannot find service in Spring PageContext from tablib.

    Please help!
    Thanks you very much!
    Last edited by SpringFlower; Mar 13th, 2012, 08:49 PM. Reason: Make it more clearly

  • #2
    Sounds like your service object is null and is not getting Autowired. Make sure your service class is annotated with @Service and that the package containing it is being scanned. Also make sure that the class with the autowired dependency is Spring managed. I can't tell you much more without seeing your configuration.

    Thanks,

    Comment


    • #3
      Originally posted by wgorder View Post
      Sounds like your service object is null and is not getting Autowired. Make sure your service class is annotated with @Service and that the package containing it is being scanned. Also make sure that the class with the autowired dependency is Spring managed. I can't tell you much more without seeing your configuration.

      Thanks,
      Dear wgorder,

      Thank you very much for your help!
      Please let me know what configuration do you want to know?
      This is my Service class:

      Code:
      ////Service.java////
      @Service
      public class Service{
      
          @TransactionalForRead
          public void getObject() throws Exception {
          .....
          }
      }
      Thank you!
      Last edited by SpringFlower; Feb 22nd, 2012, 04:05 AM.

      Comment


      • #4
        Please use [ code][/code ] tags that way we can actually make something of your code.

        Your tag library isn't spring managed (and will never be) and as such @Autowired is useless on these beans. Spring can and will only inject beans it knows about and which it can control.

        Comment


        • #5
          Dear Marten Deinum,

          Thank you very much!
          Do you know any ways to call service in this case?

          Thank you.
          Last edited by SpringFlower; Feb 22nd, 2012, 09:49 AM.

          Comment


          • #6
            Please use the forum search as that question has been answered numerous times before.

            use the WebApplicationContextUtils or RequestContextUtils to get the application context and retrieve the service as needed.

            Comment


            • #7
              Probably this will help http://thinkinginsoftware.blogspot.c...from-jstl.html
              Best,
              -Nestor

              Comment

              Working...
              X