=== Spring

1) Add Spring dependency to your project:

[dependency, artifactId="jooby-spring"]
.

2) Install Spring:

.Installing Spring
[source, java, role = "primary"]
----
package myapp;                                       <1>

import static io.jooby.Jooby.runApp;
import io.jooby.di.SpringModule;

public class App extends Jooby {

  {
    install(new SpringModule());                           <2>
      
    get("/", ctx -> {
      MyService service = require(MyService.class);  <3>
      return service.doSomething();
    });
  }

  public static void main(String[] args) {
    runApp(args, App::new);
  }
}
----

.Kotlin
[source, kotlin, role = "secondary"]
----
package myapp                                        <1>

import io.jooby.runApp
import io.jooby.di.SpringModule

fun main(args: Array<String>) {
  runApp(args) {

    install(SpringModule())                                <2>

    get ("/") {
      val service = require(MyService::class)        <3>
      service.doSomething()
    }
  }
}
----

<1> Spring scan the package `myapp` and subpackages
<2> Install Spring module
<3> The javadoc:Jooby[require, java.lang.Class] call is now resolved by Spring

Spring uses the application package and sub-packages to scan. If you need extra packages, provide them at creation time:

----
install(new Spring("foo", "bar"));
----

==== Property Injection

Configuration properties can be injected using the `@Value` annotation:

.application.conf
[source, bash]
----
currency = USD
----

.Java
[source,java,role="primary"]
----
import javax.injext.Inject;
import org.springframework.beans.factory.annotation.Value;

public class BillingService {

  @Inject
  public BillingService(@Value("currency") String currency) {
    ...
  }

}
----

.Kotlin
[source,kotlin,role="secondary"]
----
import javax.injext.Inject
import org.springframework.beans.factory.annotation.Value

class BillingService @Inject constructor(@Value("${currency}") currency: String) {
  ...
}
----

==== MVC routes

The Spring extension does a bit more in relation to MVC routes:

- A MVC route annotated with the `org.springframework.stereotype.Controller` annotation is
automatically registered. No need to register it manually

- A MVC route provided by Spring is a singleton object by default. Singleton is the default scope in Spring

.MVC route
[source, java, role="primary"]
----
import org.springframework.stereotype.Controller;

@Controller
public class Hello {

   @GET
   public String sayHi() {
     return "Hi Spring!";
   }
}
----

.Kotlin
[source, kotlin, role="secondary"]
----
import org.springframework.stereotype.Controller

@Controller
class Hello {

   @GET
   fun sayHi(): String {
     return "Hi Spring!"
   }
}
----
