在vaadin中使用spring [英] use spring in vaadin

查看:128
本文介绍了在vaadin中使用spring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在vaadin中使用spring
这是我的配置:
web.xml

i want to use spring in vaadin
it's my config:
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>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>VaadinApplicationServlet</servlet-name>
        <servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.MyUI</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>VaadinApplicationServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

applicationContext.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="jdbc:postgresql://localhost:5432/Activiti"/>
        <property name="username" value="postgres"/>
        <property name="password" value="10"/>
    </bean>

    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="databaseType" value="postgres"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="transactionManager" ref="transactionManager"/>
        <property name="databaseSchemaUpdate" value="true"/>
        <property name="deploymentResources"
                  value="classpath* : #{Init.path_Process}"/>
        <property name="history" value="audit"/>
        <property name="jobExecutorActivate" value="false"/>
    </bean>

    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
    </bean>

    <bean id="repositoryService" factory-bean="processEngine"
          factory-method="getRepositoryService"/>
    <bean id="runtimeService" factory-bean="processEngine"
          factory-method="getRuntimeService"/>
    <bean id="taskService" factory-bean="processEngine"
          factory-method="getTaskService"/>
    <bean id="historyService" factory-bean="processEngine"
          factory-method="getHistoryService"/>
    <bean id="managementService" factory-bean="processEngine"
          factory-method="getManagementService"/>
    <bean id="formService" factory-bean="processEngine"
          factory-method="getFormService"/>
    <bean id="identityService" factory-bean="processEngine"
          factory-method="getIdentityService"/>

    <bean id="Init" class="util.Init"/>
    <context:annotation-config/>
    <context:component-scan base-package="com"/>    
    <context:spring-configured/>
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
    <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>

in MyUI class:
#java
@Component
@Configurable
public class MyUI extends UI {
 protected void init(VaadinRequest vaadinRequest) {
...
@Autowired
    private IdentityService identityService;
...
}}

此配置可以在junit中正常工作!
但是
在vaadin和tomcat中运行时,identityService的java.lang.NullPointerException错误
我的问题在哪里?
谢谢

this config work in junit and Ok!
but
when run in vaadin and tomcat , java.lang.NullPointerException error for identityService
where is my problem?
thanks

推荐答案

com.MyUI由Vaadin servlet创建,并且该servlet不了解Spring.发生的情况是您的UI实例是通过反射创建的,而不是Spring托管的bean.

com.MyUI is created by the Vaadin servlet and that servlet does not know about Spring. What's happening is that your UI instance is created by reflection and isn't a Spring managed bean.

您需要使用与Spring集成的Vaadin插件.请查看 vaadin4spring项目.

You need to use a Vaadin plugin that integrates with Spring. Please check the vaadin4spring project for more details.

也许您应该将类​​更新为org.vaadin.spring.servlet.SpringAwareVaadinServlet?

Maybe you should update the class to org.vaadin.spring.servlet.SpringAwareVaadinServlet?

这篇关于在vaadin中使用spring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆