Use Apache cxf with spring mvc in a single application with shared services - spring

I'm currently working a project which based on spring MVC, it's just a standard project using spring MVC template. so I have web.xml and servlet-context.xml.
I'm working on adding Apache cxf web services into this project, and meet some problems on sharing services with existing Spring MVC.
My initial approach was trying to get web services working, so here is my web.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml
/WEB-INF/spring/jaxwsServlet/jaxwsServlet-context.xml
</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Process web service requests -->
<servlet>
<servlet-name>jaxws</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jaxws</servlet-name>
<url-pattern>/industryAspectWS</url-pattern>
</servlet-mapping>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
and my jaxwsServlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://jax-ws.dev.java.net/spring/core
classpath:spring-jax-ws-core.xsd
http://jax-ws.dev.java.net/spring/servlet
classpath:spring-jax-ws-servlet.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
<wss:binding url="/industryAspectWS">
<wss:service>
<ws:service bean="#industryAspectWS"/>
</wss:service>
</wss:binding>
<!-- Web service methods -->
<bean id="industryAspectWS" class="com.example.ws.IndustryAspectWS"></bean>
<context:component-scan base-package="com.example" />
<beans:import resource="../HibernateTransaction.xml" />
<beans:import resource="../JaxbMarshaller.xml" />
</beans>
I copied the context:component-scan beans:import sections from servlet-context.xml
This configuration works okay since I was able to boot up the server, and call Web services and also access servlet and jsp. However, I notice that since I quoted the hibernateTransaction.xml in both context xml files, there are two session factories.
I want to share all services (such as hibernate) between Apache cxf and Spring MVC controllers, so I tried to put settings in root-context.xml, it didn't work. I also tried to search this online, but didn't find any complete examples on shared services. Is it possible that we can put a setting to share services among the two?
=================================================
I had experimented some settings after I post this, and figured that if I put the lines of
<context:component-scan base-package="com.example" />
and
<tx:annotation-driven transaction-manager="txManagerExample" />
in both servlet-context.xml and jaxwsServlet-context.xml, it will work just fine. all other settings can stay in the shared root-context.xml

WSSpringServlet is not CXF. It is Metro. I would recommend using CXF. In that case you will have a CXFServlet but then you would set up CXF in your main Spring context (the one created by ContextLoaderListener.
It would work as follows: your main context would have all of the shared beans including CXF. Your Servlet context would have just your controllers. Since the servlet context is a child of the main context your controllers would also have access to everything in the main context.
See the Embedding CXF inside of Spring page, the CXF Servlet Transport Page, and my answer to this question about sharing beans between servlet context and main context.

Thanks to https://stackoverflow.com/a/30758664/2615824:
Two dispatchers (Spring MVC REST Controller and CXF JAX-WS) with one Spring Context, Java Config (no xml stuff...) example:
WebApplicationInitializer:
#Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(MyServiceConfig.class);
servletContext.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.setParent(rootContext);
ServletRegistration.Dynamic restDispatcher = servletContext.addServlet("REST dispatcher", new DispatcherServlet(webContext));
restDispatcher.setLoadOnStartup(1);
restDispatcher.addMapping("/api/*");
ServletRegistration.Dynamic cxfDispatcher = servletContext.addServlet("CXF dispatcher", CXFServlet.class);
cxfDispatcher.setLoadOnStartup(1);
cxfDispatcher.addMapping("/services/*");
}
Config:
#Configuration
#ComponentScan("my.root.package")
#ImportResource(value = {"classpath:META-INF/cxf/cxf.xml"})
#PropertySource("classpath:app-env.properties")
#PropertySource("classpath:app.properties")
#EnableWebMvc
public class MyServiceConfig {
#Autowired
private Bus cxfBus;
#Autowired
private CxfEndpointImpl cxfEndpoint;
#Bean
public Endpoint cxfService() {
EndpointImpl endpoint = new EndpointImpl(cxfBus, cxfEndpoint);
endpoint.setAddress("/CxfEndpointImpl");
endpoint.setWsdlLocation("classpath:CxfService/CxfService-v1.0.wsdl");
endpoint.publish();
return endpoint;
}
#Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
Sample CXF Endpoint (WSDL first):
#Component
#WebService(
endpointInterface = ".....v1_0.CxfServicePort",
targetNamespace = "http://..../service/CxfService/v1_0",
serviceName = "CxfService",
portName = "CxfServicePort",
wsdlLocation = "classpath:CxfService/CxfService-v1.0.wsdl")
#MTOM(enabled = true)
#SchemaValidation(type = SchemaValidationType.BOTH)
#InInterceptors(classes = NoBinaryContentLoggingInInterceptor.class)
#OutInterceptors(classes = NoBinaryContentLoggingOutInterceptor.class)
#EndpointProperty(key = "ws-security.callback-handler", ref = "cxfEndpointSecurityHandler")
public class CxfEndpointImpl implements CxfServicePort {
//...
}
Sample REST Controller:
#RestController
#RequestMapping(value = "/system", produces = MediaType.APPLICATION_JSON_VALUE)
public class RestController {
//...
}
CXF Endpoint deployment address:
ip:port/tomcat-context/services/CxfEndpointImpl?wsdl
Spring REST Controller deployment address:
ip:port/tomcat-context/api/system

Related

http status 500-Error instantiating servlet class org.springframework.web.servlet.DispatcherServlet

Above is the directory hierarchy of my program
I am new to spring and learning MVC concepts I have written a program which takes input(Name) into a text box and prints Hello...'name'. Tha following is my directory structure and the various files I have created.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>MVC_HelloWorld</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- default configuration -->
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action -->
</servlet-mapping>
</web-app>
HelloWorld-servlet.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- default handler mapping -->
<!-- file should be created under web inf annd it's view resolver file -->
<!-- handler(Not rqd in case of default handler) -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<!-- controller configuration -->
<bean name="/HelloWorld.ap" class="controller.HelloController"> <!-- mapping url pattern to controller class using 'name' -->
<!-- view resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" vlaue="/"/> <!-- default location (prefix used foor rqd page locations) -->
|<property name="sufix" value=".jsp"/> <!-- sufix used forr rqd page extensions -->
</bean>
</bean>
</beans>
HelloController.java
package controller;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.sun.javafx.collections.MappingChange.Map;
public class HelloController implements Controller {
#Override
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception {
String name=req.getParameter("name");
Map m= new HashMap(); // creating output object
m.put("msg","Hello..."+name);
ModelAndView mav=new ModelAndView("success"+m);
return mav;
}
}
index.jsp
<h1> Hello World</h1>
<form action="./hello.ap">
NAME: <input type="text" name="name">
<input type="Submit" value="Say Hello">
</form>
success.jsp
${msg}
when I am running this code the index.jsp page is running properly bur upon further execution It shows Error 500. what's wrong with the code..?? I am using Eclipse oxygen in that apache 8.5
You configuration in web.xml are wrong.
You are trying to map the dispatch servlet as the controller.
In spring mvc like in other mvc frameworks (struts etc.) there is one major servlet that use to dispatch all requests.
org.springframework.web.servlet.DispatcherServlet is usually named “dispatcher” and should be mapped to a top level url usually “\”
e.g.
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
And the controller is mapped under this url e.g. HelloWorld
#Controller
#RequestMapping("/HelloWorld");"
public class HelloController implements Controller {}
As your initial project is far from the classic vanilla starter Spring MVC project and it looks like you are using a very old Spring version (or spring tutorial). I suggest to start fresh from some online tutorial.
E.g.
http://www.journaldev.com/2433/spring-mvc-tutorial
http://www.mkyong.com/spring-mvc/gradle-spring-mvc-web-project-example/
Try below edit to web.xml.
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>*.ap</url-pattern> <!-- this same extension should bbe used in form action -->
</servlet-mapping>

Spring 4.2.1 RestController tried to return template instead return JSON

I tried to create a Spring Rest Controller, based on this example i create a controller like this.
DeveloperRestController.java
#RestController
public class DeveloperRestController {
#RequestMapping("/developer/list")
public Developer index() {
Developer developer = new Developer("Developername", "developer#yahoo.com");
return developer;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!--Here we specify about the DispatcherServlet class in the Web Deployment Descriptor-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
</web-app>
dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="com.developerdata.controller" />
<context:annotation-config />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
But it shows 404 page not found, seems that spring tried to load a template...
Result:
Error 404 /WEB-INF/jsp/developer/list.jsp
what should i do?
Seems like you have a configuration issue. The sample you are basing yours on is spring boot based. So it handles the configuration for you. To get yours working you will need to add jackson to the classpath. If you are using maven then:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.2</version>
</dependency>
Then you need to alter your spring config to include:
<mvc:annotation-driven />
From the spring documentation:
The above registers a RequestMappingHandlerMapping, a
RequestMappingHandlerAdapter, and an ExceptionHandlerExceptionResolver
(among others) in support of processing requests with annotated
controller methods using annotations such as #RequestMapping,
#ExceptionHandler, and others.
This also then enables the MappingJackson2HttpMessageConverter if jackson 2 is in your classpath.
References:
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-config-enable
https://spring.io/guides/gs/rest-service/
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/ (This one seems more appropriate for you to get started based on your problem)
With #ResponseBody, Spring will handle the JSON you need. Jackson
library is required too.
#RestController
public class DeveloperRestController {
#RequestMapping("/developer/list")
public #ResponseBody Developer index() {
Developer developer = new Developer("Developername", "developer#yahoo.com");
return developer;
}
}

Vaadin and Spring integration - #Inject doesn't work

I'm trying to integrate Vaadin with Spring. In my main Vaadin application class I have:
public class MyVaadinApplication extends UI {
#Inject
private PrivatePersonBo privatePersonBo;
#Override
public void init(VaadinRequest request) {
Layout layout = new FormLayout();
layout.setCaption("New Private Person");
setContent(layout);
ApplicationContext appContext = new ClassPathXmlApplicationContext("resources/spring/Context.xml");
appContext.getBean(MyVaadinApplication.class);
PrivatePersonBo privatePersonBo = (PrivatePersonBo) appContext.getBean("privatePersonBo");
PrivatePerson existingEmployee = privatePersonBo.findByName("TestUserName");
}
}
If I get bean from context directly I recieve bean, however If I comment line which recieves bean from appContext then #Inject annotation doesn't work and I get NullPointerException. My deployment descriptor is below:
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:resources/spring/Context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</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>pl.adamsalata.MyVaadinApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>VaadinApplicationServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Any suggestions please?
You can integrate Vaadin 7 with Spring in two simple steps:
1) Create a UIProvider that lookup UIs in spring context:
public class SpringUIProvider extends DefaultUIProvider {
#Override
public UI createInstance(UICreateEvent event) {
ApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(VaadinServlet.getCurrent().getServletContext());
return ctx.getBean(event.getUIClass());
}
}
2) Declare the UIProvider in web.xml:
<context-param>
<param-name>UIProvider</param-name>
<param-value>org.example.SpringUIProvider</param-value>
</context-param>
And remember to use prototype scope for UI classes.
If you want to integrate Vaadin with Spring then use #Configurable feature. Then all instantiated objects (even if you create them using new MyObject() code) will be integrated with Spring context. You can find more details about such setup in Spring documentation: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-using-aspectj

RequestMapping in spring mvc

I am trying to understand requestmapping in spring mvc, I have an application, actually I am just getting started with spring mvc.
I have these two urls
The first one with a forward slash at the end seems to be working fine.
http://localhost:8080/contactmanager/index/
The second one without a forward slash at the end does not work
http://localhost:8080/contactmanager/index
This second one gives me the 'HTTP Status 404 -' error, how can I force the application to be appending a forwards slash at the end of the url?
The method in the controller looks like this
#RequestMapping("/index")
public String listContacts(Map<String, Object> map) {
map.put("contact", new Contact());
map.put("contactList", contactService.listContact());
//org.springframework.web.context.ContextLoaderListener
//org.springframework.web.context.ContextLoaderListener
//org.springframework.web.servlet.DispatcherServlet
//org.springframework.web.servlet.DispatcherServlet
return "contact";
}
and my web.xml looks like this
<servlet>
<servlet-name>contactmanager</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/contactmanager-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>contactmanager</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Thanks in advance.
Using java configuration:
#Configuration
#EnableWebMvc
public class WebConfig {}
or using XML configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven />
From Spring's reference documentation:
The above registers a RequestMappingHandlerMapping, a
RequestMappingHandlerAdapter, and an ExceptionHandlerExceptionResolver
(among others) in support of processing requests with annotated
controller methods using annotations such as #RequestMapping ,
#ExceptionHandler, and others.
In RequestMappingHandlerMapping there is useful boolean flag - decription from Javadoc:
/**
* Whether to match to URLs irrespective of the presence of a trailing slash.
* If enabled a method mapped to "/users" also matches to "/users/".
* <p>The default value is {#code true}.
*/
public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch) {
this.useTrailingSlashMatch = useTrailingSlashMatch;
}
Since this is enabled by default just make sure that your configuration uses RequestMappingHandlerMapping.
If this doesn't help you, check that spring's default servlet is configured: <mvc:default-servlet-handler/> and try add to web.xml
<!-- Disables Servlet Container welcome file handling. Needed for compatibility with Servlet 3.0 and Tomcat 7.0 -->
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>

Setting up Vaadin and Spring 3 - Autowiring fails (annotations)

I'm having some trouble using the #Autowire annotation of spring 3 in a vaadin application.
I have made a tiny test project with just a button which executes a method in an autowired service class.
I'm getting a NullPointerException when I click the button, because the service is never injected.
I have annotated the service with #Service("calculationService")
This is my application class:
package vaadinBaas;
// imports
public class MyVaadinApplication extends Application {
private Window window;
private CalculationService calculationService;
#Autowired
public void setCalculationService(CalculationService calculationService) {
this.calculationService = calculationService;
}
#Override
public void init() {
window = new Window("Show me the magic");
setMainWindow(window);
Button button = new Button("Click Me");
button.addListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
window.addComponent(new Label(String.valueOf(calculationService.multiply(10, 10))));
}
});
window.addComponent(button);
}
}
This is my spring application context:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ct="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<ct:component-scan base-package="vaadinBaas" />
<ct:annotation-config />
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
</beans>
And finally my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Vaadin Web Application</display-name>
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>Vaadin Application Servlet</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>vaadinBaas.MyVaadinApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Vaadin Application Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
</web-app>
Am I missing something obvious here?
Try annotating MyVaadinApplication with Component annotation. Since MyVaadinApplication is not considered as spring managed class the Autowire didnt work for you. Also you need to load the bean definition xml using ClassPathXmlApplicationContext and try calling getBean(MyVaadinApplication.class) so that all the autowiring happens automatically

Resources