Hi.
We use Spring a lot using the @javax.annotation.Resource annotation for injecting stuff. It works well but we see new behaviour using the annotation to inject stuff into object in 2.13:
This works fine in Scala-2.12, but in 2.13 it fails at runtime with:
Caused by: java.lang.IllegalStateException: @Resource annotation is not supported on static fields
Ran into the same issue - this is the minimal version that doesn’t work in Scala 2.13:
import com.google.inject.{Guice, Inject, Injector}
class A {}
object O {
@Inject var a: A = _
}
val injector: Injector = Guice.createInjector()
injector.injectMembers(O)
println(O.a) // prints null
We were able to fix this by changing it to the syntax above: @(Inject @setter) var a: A = _
However, there’s one remaining issue - did anyone figure out how to use the @Named annotation in combination with this? @(Inject @Named("foo") @setter) var a: A = _ or @Named("foo") @(Inject @setter) var a: A = _ don’t work
import com.google.inject.{Guice, Inject, Injector}
class A {}
class O {
@Inject var variable: A = _
@Inject val value: A = null
}
object O extends O
val injector: Injector = Guice.createInjector()
injector.injectMembers(O)
println(O.variable)
println(O.value)