Hi , does kotlin’s `context class` work well with ...
# spring
s
Hi , does kotlin’s
context class
work well with spring ? Because of some context requirement , I have to mark my spring bean
context
:
Copy code
context(IConfig)
@Named
class MyService (...) {

   val config = SomeBuilder().build() // it needs IConfig context
}
test :
Copy code
internal class MyServiceTest : AbstractCoreTest()  {

  @Inject
  private lateinit var service: MyService
  
  // do tests
}
It compiles OK , but when executing , it throws :
Copy code
java.lang.IllegalStateException: Failed to load ApplicationContext for [MergedContextConfiguration@484876a1 testClass = foo.MyServiceTest, locations = ["classpath:core.xml"], classes = [], contextInitializerClasses = [destiny.TestAppInit], activeProfiles = [], propertySourceLocations = [], propertySourceProperties = [], contextCustomizers = [], contextLoader = org.springframework.test.context.support.DelegatingSmartContextLoader, parent = null]
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext
Copy code
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myService' defined in file [.../MyService.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'IConfig' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Is there a better way to solve this ? Thanks. (Kotlin 1.8.21 , Spring 6.0.9)