O'Reilly logo

Easy Web Development with WaveMaker by Edward Callahan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dependency injection

Now that we've seen how useful other service beans can be in our Java code, let's make it easier to get to those services. The best way to get an instance of the runtime bean, or any other project bean, is to "inject" it into the service class using dependency injection.

Dependency injection is when the bean declares a dependency and the container (for example, Tomcat and Spring) provides or injects that dependency to the bean as part of its initialization. The benefit is that the property is populated for us by the container. We do not need to fetch an instance of the service in code.

In our example, DbOpsSvc from the JavaServices project, we also inject runtimeService into our service class. The updateCustomerInjected() method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required