我在项目中有两个模块:
我有一个scala类:
TimeSeries.scala
trait TimeSeries {
def series(sourceData: BoundedTimeSeries, destType: Type) : BoundedTimeSeries
def series(sourceData: BoundedTimeSeries, destType: Type,
destDuration: Duration) : BoundedTimeSeries
}
object TimeSeries extends TimeSeries {
def series(sourceData: BoundedTimeSeries, destType: Type) : BoundedTimeSeries = {
new CalculatedBoundedTimeSeries(sourceData, destType);
}
def series(sourceData: BoundedTimeSeries, destType: Type,
destDuration: Duration) : BoundedTimeSeries = {
new ComputedBoundedTimeSeries(sourceData, destType, destDuration);
}
}
这是XML文件中的bean条目:
<bean id="timeSeries" class="com.people.user.booking.TimeSeries" />
在此模块中,我在Autowiring
类下面使用了TimeSeries
个scala类java
:
class Xyz
{
@Autowired
private TimeSeries timeSeries;
//Some code
private void callTimeSeries()
{
BoundedTimeSeries series = someMethodToGetSeries();
Type type = someMethodToGetType();
timeSeries.series(series, type);
}
}
但我得到例外:
unsatisfied dependencies: Dependency on
[(objectClass=com.people.user.booking.TimeSeries)] (from bean [&timeSeries])
Caused by: org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class [com.people.user.booking.TimeSeries]
: Specified class is an interface
at org.springframework.beans.factory.support.
SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:67)
at org.springframework.beans.factory.support.
AbstractAutowireCapableBeanFactory.
instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
... 15 more
所以TimeSeries scala对XYZ类的依赖注入(DI)没有正确发生。
我对一个java使用相同的DI到另一个java类,这种情况很好但是从Scala到Java的DI导致了这样的问题。
使用Spring的Scala依赖注入是否有不同的方式?