我想用斯卡拉Spring。我知道Autowired可以和Scala類一起工作,但是我使用的是一個需要一個對象的web框架,我想向它注入一個dao。我想知道如何做到這一點?對不起,我對Scala很陌生,在此先感謝。如何在Scala對象中使用Spring Autowired(或手動連線)?
@Service
object UserRest extends RestHelper {
@Autowired
@BeanProperty
val userRepository: UserRepository = null;
.....
}
<beans>
.....
<bean id="userRest" class="com.abc.rest.UserRest" >
<!--- this is my attempt to manually wire it --->
<property name="userRepository" ref="userRepository"/>
</bean>
</beans>
爲什麼你需要一個對象在這裏? 無論如何'@Service class Hello {@Autowired var repo:Repository = _}' 應該可以正常工作,假設您已經配置了組件掃描或使用AnnotationConfigApplicationContext – OlegYch