WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());return (com.xq.controller.HelloWorld) wac.getBean(com.xq.controller.HelloWorld.class);
这个是通过类去找bean.
在web。xml中
<servlet>
<servlet-name>HelloWorde</servlet-name>
<servlet-class>com.xq.vaadin.SimpleAddressBook</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>com.xq.vaadin.HelloWorld</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorde</servlet-name>
<url-pattern>/VAADIN2/*</url-pattern>
</servlet-mapping>
spring 中国际化,还有vaadin的页面配置:
<bean id="messageSource2" name="messageSource2" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="message-info"></property>
<property name="useCodeAsDefaultMessage" value="true"></property>
</bean>
<bean id="test" name="test" class="com.xq.controller.HelloWorld"></bean>
package com.xq.util;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
public class SpringContext {
private ApplicationContext context;
public void SpringContextHelper(Application application) {
ServletContext servletContext = ((WebApplicationContext) application.getContext()).getHttpSession().getServletContext();
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}
public Object getBean(final String beanRef) {
return context.getBean(beanRef);
}
public Object getBean(final Class class1){
return context.getBean(class1);
}
}
package com.xq.util;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
public class SpringContext {
private ApplicationContext context;
public void SpringContextHelper(Application application) {
ServletContext servletContext = ((WebApplicationContext) application.getContext()).getHttpSession().getServletContext();
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}
public Object getBean(final String beanRef) {
return context.getBean(beanRef);
}
public Object getBean(final Class class1){
return context.getBean(class1);
}
}