我是 scala 和 vaadin 的新手,我只是在尝试。我正在尝试在我的 scala vaadin 应用程序中使用 spring 应用程序上下文和 spring di,但无法获取要注入的数据源。我不知道,也许我在做一些根本错误的事情,但这是我的代码:
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<description>
Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>Scalatest Application</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<description>Vaadin application class to start</description>
<param-name>application</param-name>
<param-value>com.example.scalatest.ScalaApp</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Scalatest Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
应用上下文:
<bean id="main" class="com.example.scalatest.ScalaApp">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="url"/>
<property name="username" value="root"/>
<property name="password" value="pass"/>
</bean>
在我的 scala 课上
var dataSource:DataSource = _;
def setDataSource(datasource:DataSource){
dataSource = datasource;
}
不工作, ds 在启动时为空。有人可以指导我吗?