I'm trying to implement an application with several `ui`s - vaadin, jsp and etc.

It was working with simple `jsp` but then I decided to use vaadin as ui. 

I've created vaadin servlet(and spring servlet left too).
My `web.xml` looks like this

```
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/pmc-web-context.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>another-pmc-servlet</servlet-name>
        <servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.xxxx.app.pmc.vaadin.PmcUi</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
    </servlet>

    <servlet>
        <servlet-name>pmc-servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>another-pmc-servlet</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>pmc-servlet</servlet-name>
        <url-pattern>/JSP/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>/WEB-INF/jsp/*</url-pattern>
    </servlet-mapping>

</web-app>

```

I've created vaadin `table` component and adjusted it for my needs. I used autowiring for service.

```
package com.xxxx.app.pmc.vaadin.components;

import com.xxxx.app.pmc.model.Project;
import com.xxxx.app.pmc.service.project.ProjectService;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Table;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("projectTable")
public class ProjectTable extends Table {

    private static final String CAPTION = "Projects";
    private static final String[] headers = { "Project name", "Project owner", "ID" };

    @Autowired
    private ProjectService projectService;

    public Table createTable() {
        this.setContainerDataSource(projectDatasource());
        this.setVisibleColumns(headers);
        this.setSelectable(true);
        this.setImmediate(true);

        return this;
    }

    public IndexedContainer projectDatasource() {
        IndexedContainer indexedContainer = new IndexedContainer();

        for(String header: headers) {
            indexedContainer.addContainerProperty(header, String.class, "");
        }

        List<Project> projects = projectService.findAllProjects();

        for(int i = 0; i < projects.size(); i++) {
            Object id = indexedContainer.addItem();
            Project item = projects.get(i);
            indexedContainer.getContainerProperty(id, headers[0]).setValue(item.getProjectName());
            indexedContainer.getContainerProperty(id, headers[1]).setValue(item.getProjectOwner());
            indexedContainer.getContainerProperty(id, headers[1]).setValue(item.getProjectId());
        }

        return indexedContainer;
    }

}

```

`ProjectService` is a spring bean too.

```
@Service("projectService")
public class ProjectService {

    @Autowired
    private ProjectRepository projectRepository;

    public void insertProject(Project project) {
        projectRepository.store(project);
    }

    public List<Project> findAllProjects() {
        return projectRepository.getAllItems();
    }

    public Project getProject(String id) {
        return projectRepository.get(id);
    }

}

```

`ProjectRepository` is another spring bean. It uses `SqlSessionTemplate` bean from MyBatis. 

```
@Repository("projectRepository")
public class ProjectRepository implements IRepository<Project> {

    private static final String STORE_PROJECT = "Project.insertProject";
    private static final String GET_PROJECT_BY_ID = "Project.getProjectById";
    private static final String GET_PROJECT_LIST = "Project.getProjectList";

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @Override
    public void store(Project object) {
        sqlSessionTemplate.insert(STORE_PROJECT, object);
    }

    @Override
    public Project get(String id) {
        return sqlSessionTemplate.selectOne(GET_PROJECT_BY_ID, id);
    }

    @Override
    public List<Project> getAllItems() {
        return sqlSessionTemplate.selectList(GET_PROJECT_LIST);
    }

} 

```

When I wrote an application using spring `controller`(using JSP) - it was working fine. 
But when I added vaadin - `JSP` stopped working and vaadin application throws `NullPointerException` for `ProjectService`, `ProjectRepository`... all the beans I use.

**What is the problem?**
All my context `xml` context files are simple. 

```
<import resource="classpath:com/xxxx/app/pmc/pmc-service-context.xml"/>
<context:component-scan base-package="com.xxx.app.pmc"/>

```

And my `pmc-web-context.xml` has this lines too.

```
<mvc:annotation-driven/>
<context:annotation-config/>

```

It was working fine with JSP so I think the problem is not with spring declarations itself but with integration of spring into vaadin of mine. 

**How to resolve it?** 
When I for example created `ProjectTable` object manually - it throws `NullPointerException` for `ProjectService`. When I create `ProjectService` manually - it throws `NullPointerException` for `ProjectRepository` and so on. It seems autowiring simply doesn't work.

P.S forgot to add my UI code

```
package com.xxxx.app.pmc.vaadin;

import com.xxxx.app.pmc.vaadin.components.ProjectTable;
import com.vaadin.annotations.Title;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

import org.springframework.stereotype.Component;

@Title("PMC")
@Component("pmcVaadin")
public class PmcUi extends UI {

    @Override
    protected void init(VaadinRequest request) {
        VerticalLayout mainLayout = new VerticalLayout();
        ProjectTable projectTable = new ProjectTable();
        mainLayout.addComponent(projectTable.createTable());
        mainLayout.setSizeFull();
        setContent(mainLayout);
    }

}

```