我是 Vaadin 和 Mybatis-Spring 的新手。
我的 UI 类无法使用 @Autowired 注释调用 Service 类。我为服务类附加了@Service。
我的观点:
@SuppressWarnings("serial")
@Theme("test")
@Component
@Scope("prototype")
@SpringView(name = TestUI.ID)
public class TestUI extends UI {
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = TestUI.class)
public static class Servlet extends VaadinServlet {
}
@Autowired
UserService service;
UserModel model;
我的应用程序 context.xml 在资源文件夹下。
<ct:annotation-config/>
<ct:component-scan base-package="com.example.test" />
<ct:component-scan base-package="com.example.service" />
<ct:component-scan base-package="com.example.model" />
<ct:component-scan base-package="com.example.mapper" />
开发上下文.xml
<context:annotation-config />
<bean id="DEVdataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="" />
<property name="" value="" />
<property name="" value="" />
<property name="" value="" />
<property name="maxActive" value="50" />
<property name="validationQuery" value="select 1 from dual"/>
<property name="testOnBorrow" value="true"/>
<property name="connectionInitSqls">
<list>
<value>ALTER SESSION SET CURRENT_SCHEMA=null</value>
</list>
</property>
</bean>
<!-- setup mybatis bean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="DEVdataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>
<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.example.mapper.Mapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<!-- automatically find mappers -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.example.mapper.**.mapper" />
</bean>
服务开发上下文.xml
<context:component-scan base-package="com.example"></context:component-scan>
Web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:resources/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
代码不起作用,请帮我弄清楚我错过了什么