Grails
  1. Grails
  2. GRAILS-4141

Webflow: Dependency injection not working

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.1-beta2
    • Fix Version/s: 1.1.1
    • Component/s: WebFlow
    • Labels:
      None
    • Environment:
      Windows XP SP3, Java 1.6_10

      Description

      I attached an example app to demonstrate this bug.
      If you are calling a method from within a flow and this method is defined outside of the flow, you cannot access any controller-injected instances.

      A workaround is to inject the service manually:

      sample
      ...
      def authenticationService 
      ...
      	def isLoggedIn() {   
      		def authenticationServiceClass = grailsApplication.classLoader.loadClass("AuthenticationService")
      		authenticationService = authenticationServiceClass.newInstance()
      		
      		return authenticationService.authenticate() 
      	}
      

      I don't know if this issue also exists if you don't use a flow.

        Issue Links

          Activity

          Hide
          David Trattnig added a comment -

          @Cazacu: this is just working fine for me in Grails 1.3.3/1.3.4. Probably you service itself has some compilation problems? Any difference if you inject it in a typed way e.g. "SomeService someService"?

          Show
          David Trattnig added a comment - @Cazacu: this is just working fine for me in Grails 1.3.3/1.3.4. Probably you service itself has some compilation problems? Any difference if you inject it in a typed way e.g. "SomeService someService"?
          Hide
          Eduardo Aranda added a comment -

          I've been also working with webflows in Grails 1.3.5, and found the same issue as @cazacu.
          I also tried typing the Service and still doesn't work

          Show
          Eduardo Aranda added a comment - I've been also working with webflows in Grails 1.3.5, and found the same issue as @cazacu. I also tried typing the Service and still doesn't work
          Hide
          Bill James added a comment -

          @cazacu and @eduardo this is NOT the same issue.

          The original issue was that, when calling a non-flow action from a flow action, injection would not work.

          Your issue is that, in a controller with flow and non-flow actions, the flow actions don't seem to have injected objects. (something I haven't verified).

          I would suggest creating a new JIRA for this, as it is a different issue.

          Show
          Bill James added a comment - @cazacu and @eduardo this is NOT the same issue. The original issue was that, when calling a non-flow action from a flow action, injection would not work. Your issue is that, in a controller with flow and non-flow actions, the flow actions don't seem to have injected objects. (something I haven't verified). I would suggest creating a new JIRA for this, as it is a different issue.
          Hide
          Graeme Rocher added a comment -

          Bulk closing bunch of resolved issues

          Show
          Graeme Rocher added a comment - Bulk closing bunch of resolved issues
          Hide
          Matthew Payne added a comment -

          @Graeme Rocher – this is still very broken in 2.1.x

          Show
          Matthew Payne added a comment - @Graeme Rocher – this is still very broken in 2.1.x

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Malte Huebner
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development