You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

advanced-spring.asciidoc 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. ---
  2. title: Vaadin Spring Add-on
  3. order: 18
  4. layout: page
  5. ---
  6. [[advanced.spring]]
  7. = Vaadin Spring Add-on
  8. ((("Vaadin Spring", id="term.advanced.spring.springlong", range="startofrange")))
  9. ((("Spring", id="term.advanced.spring.spring", range="startofrange")))
  10. Vaadin Spring and Vaadin Spring Boot add-ons make it easier to use Spring in
  11. Vaadin applications. Vaadin Spring enables Spring dependency injection with
  12. custom UI and view providers, and provides three custom scopes:
  13. [classname]#UIScope#, [classname]#ViewScope#, and
  14. [classname]#VaadinSessionScope#.
  15. API documentation for add-ons is available at:
  16. * Vaadin Spring API at link:https://vaadin.com/api/vaadin-spring[vaadin.com/api/vaadin-spring]
  17. * Vaadin Spring Boot API at link:https://vaadin.com/api/vaadin-spring-boot[vaadin.com/api/vaadin-spring-boot]
  18. To learn more about Vaadin Spring, the
  19. link:https://vaadin.github.io/spring-tutorial/[Vaadin Spring Tutorial]
  20. gives a hands-on introduction. The source code of the Spring Tutorial demo is
  21. available for browsing or cloning at
  22. link:https://github.com/Vaadin/spring-tutorial[github.com/Vaadin/spring-tutorial].
  23. [[advanced.spring.spring]]
  24. == Spring Overview
  25. __Spring Framework__ is a Java application framework that provides many useful
  26. services for building applications, such as authentication, authorization, data
  27. access, messaging, testing, and so forth. In the Spring core, one of the central
  28. features is dependency injection, which accomplishes inversion of control for
  29. dependency management in managed beans. Other Spring features rely on it
  30. extensively. As such, Spring offers capabilities similar to CDI, but with
  31. integration with other Spring services. Spring is well-suited for applications
  32. where Vaadin provides the UI layer and Spring is used for other aspects of the
  33. application logic.
  34. __Spring Boot__ is a Spring application development tool that allows creating
  35. Spring applications easily. __Vaadin Spring Boot__ builds on Spring Boot to
  36. allow creating Vaadin Spring applications easily. It starts up a servlet,
  37. handles the configuration of the application context, registers a UI provider,
  38. and so forth.
  39. Regarding general Spring topics, we recommend the following Spring
  40. documentation:
  41. ifdef::web[]
  42. * link:http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/[Spring
  43. Framework Reference Documentation].
  44. * link:http://projects.spring.io/spring-framework/[Spring Project]
  45. * link:https://vaadin.github.io/spring-tutorial/[Vaadin Spring Tutorial]
  46. endif::web[]
  47. [[advanced.spring.spring.injection]]
  48. === Dependency Injection
  49. __Dependency injection__ is a way to pass dependencies (service objects) to
  50. dependent objects (clients) by injecting them in member variables or initializer
  51. parameters, instead of managing the lifecycle in the clients or passing them
  52. explicitly as parameters. In Spring, injection of a service object to a client
  53. is configured with the [classname]#@Autowired# annotation.
  54. For a very typical example in a web application, you could have a user data
  55. object associated with a user session:
  56. [source, java]
  57. ----
  58. @SpringComponent
  59. @VaadinSessionScope
  60. public class User implements Serializable {
  61. private String name;
  62. public void setName(String name) {this.name = name;}
  63. public String getName() {return name;}
  64. }
  65. ----
  66. The [classname]#@SpringComponent# annotation allows for automatic detection of
  67. managed beans by Spring. (The annotation is exactly the same as the regular
  68. Spring [classname]#@Component#, but has been given an alias, because Vaadin has
  69. a [interfacename]#Component# interface, which can cause trouble.)
  70. Now, if we have a UI view that depends on user data, we could inject the data in
  71. the client as follows:
  72. [source, java]
  73. ----
  74. public class MainView extends CustomComponent implements View {
  75. User user;
  76. Label greeting = new Label();
  77. @Autowired
  78. public MainView(User user) {
  79. this.user = user;
  80. ...
  81. }
  82. ...
  83. @Override
  84. public void enter(ViewChangeEvent event) {
  85. // Then you can use the injected data
  86. // for some purpose
  87. greeting.setValue("Hello, " + user.getName());
  88. }
  89. }
  90. ----
  91. Here, we injected the user object in the constructor. The user object would be
  92. created automatically when the view is created, with all such references
  93. referring to the same shared instance in the scope of the Vaadin user session.
  94. [[advanced.spring.spring.contexts]]
  95. === Contexts and Scopes
  96. __Contexts__ in Spring are services that manage the lifecycle of objects and
  97. handle their injection. Generally speaking, a context is a situation in which an
  98. instance is used with a unique identity. Such objects are essentially
  99. "singletons" in the context. While conventional singletons are application-wide,
  100. objects managed by a Spring container can be "singletons" in a more narrow
  101. __scope__: a user session, a particular UI instance associated with the session,
  102. a view within the UI, or even just a single request. Such a context defines the
  103. lifecycle of the object: its creation, use, and finally its destruction.
  104. Earlier, we introduced a user class defined as session-scoped:
  105. [source, java]
  106. ----
  107. @SpringComponent
  108. @VaadinSessionScope
  109. public class User {
  110. ----
  111. Now, when you need to refer to the user, you can use Spring injection to inject
  112. the session-scoped "singleton" to a member variable or a constructor parameter;
  113. the former in the following:
  114. [source, java]
  115. ----
  116. public class MainView extends CustomComponent implements View {
  117. @Autowired
  118. User user;
  119. Label greeting = new Label();
  120. ...
  121. @Override
  122. public void enter(ViewChangeEvent event) {
  123. greeting.setValue("Hello, " + user.getName());
  124. }
  125. }
  126. ----
  127. [[advanced.spring.boot]]
  128. == Quick Start with Vaadin Spring Boot
  129. The Vaadin Spring Boot is an add-on that allows for easily creating a project
  130. that uses Vaadin Spring. It is meant to be used together with Spring Boot, which
  131. enables general Spring functionalities in a web application.
  132. You can use the Spring Initializr at
  133. link:https://start.spring.io/[start.spring.io] website to generate a project,
  134. which you can then download as a package and import in your IDE. Pick Vaadin as
  135. a dependency on the site to include all the required Vaadin Spring dependencies
  136. and auto-configuration.The generated project is a Spring application stub; you
  137. need to add at least a UI class to the generated project.
  138. See the link:https://vaadin.github.io/spring-tutorial/[Vaadin Spring
  139. Tutorial] for detailed instructions for using Spring Boot.
  140. [[advanced.spring.installation]]
  141. == Installing Vaadin Spring Add-on
  142. To install the Vaadin Spring and/or Vaadin Spring Boot add-ons, either define
  143. them as an Ivy or Maven dependency or download from the Vaadin Directory add-on
  144. page at link:https://vaadin.com/directory#addon/vaadin-spring[vaadin.com/directory#addon/vaadin-spring]
  145. or link:https://vaadin.com/directory#addon/vaadin-spring-boot[vaadin.com/directory#addon/vaadin-spring-boot].
  146. See <<../addons/addons-overview.asciidoc#addons.overview,"Using
  147. Vaadin Add-ons">> for general instructions for installing and using Vaadin
  148. add-ons.
  149. The Ivy dependency is as follows:
  150. [subs="normal"]
  151. ----
  152. &lt;dependency org="com.vaadin" name="vaadin-spring"
  153. rev="[replaceable]##latest.release##"/&gt;
  154. ----
  155. The Maven dependency is as follows:
  156. [subs="normal"]
  157. ----
  158. &lt;dependency&gt;
  159. &lt;groupId&gt;com.vaadin&lt;/groupId&gt;
  160. &lt;artifactId&gt;vaadin-spring&lt;/artifactId&gt;
  161. &lt;version&gt;[replaceable]##LATEST##&lt;/version&gt;
  162. &lt;/dependency&gt;
  163. ----
  164. For Vaadin Spring Boot, depending on [literal]#++vaadin-spring-boot-starter++# will
  165. include all the required Vaadin dependencies.
  166. [[advanced.spring.preparing]]
  167. == Preparing Application for Spring
  168. A Vaadin application that uses Spring must have a file named
  169. [filename]#applicationContext.xml# in the [filename]#WEB-INF# directory.
  170. Using Spring Initializr automatically generates a suitable file, but if
  171. you configure Vaadin Spring manually, you can follow the model below.
  172. [subs="verbatim,replacements,quotes"]
  173. ----
  174. &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  175. &lt;beans xmlns="http://www.springframework.org/schema/beans"
  176. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  177. xmlns:context="http://www.springframework.org/schema/context"
  178. xsi:schemaLocation="
  179. http://www.springframework.org/schema/beans
  180. http://www.springframework.org/schema/beans/spring-beans.xsd
  181. http://www.springframework.org/schema/context
  182. http://www.springframework.org/schema/context/spring-context-4.1.xsd"&gt;
  183. &lt;!-- Configuration object --&gt;
  184. &lt;bean class="[replaceable]#com.example.myapp.MySpringUI.MyConfiguration#" /&gt;
  185. &lt;!-- Location for automatically scanned beans --&gt;
  186. &lt;context:component-scan
  187. base-package="[replaceable]#com.example.myapp.domain#" /&gt;
  188. &lt;/beans&gt;
  189. ----
  190. The application should not have a servlet extending [classname]#VaadinServlet#,
  191. as Vaadin servlet has its own [classname]#SpringVaadinServlet# that is deployed
  192. automatically. If you need multiple servlets or need to customize the Vaadin
  193. Spring servlet, see <<advanced.spring.deployment>>.
  194. You can configure managed beans explicitly in the file, or configure them to be
  195. scanned using the annotations, which is the preferred way described in this
  196. section.
  197. [[advanced.spring.springui]]
  198. == Injecting a UI with [classname]#@SpringUI#
  199. ((("[classname]#@SpringUI#", id="term.advanced.spring.springui", range="startofrange")))
  200. Vaadin Spring offers an easier way to instantiate UIs and to define the URL
  201. mapping for them than the usual ways described in
  202. <<../application/application-environment#application.environment,"Deploying
  203. an Application">>. It is also needed for enabling Spring features in the UI. To
  204. define a UI class that should be instantiated for a given URL, you simply need
  205. to annotate the class with [classname]#@SpringUI#. It takes an optional path as
  206. parameter.
  207. [source, java]
  208. ----
  209. @SpringUI(path="/myniceui")
  210. @Theme("valo")
  211. public class MyNiceUI extends UI {
  212. ...
  213. ----
  214. The path in the URL for accessing the UI consists of the context path of the
  215. application and the UI path, for example, [literal]#++/myapp/myniceui++#. Giving
  216. empty UI path maps the UI to the root of the application context, for example,
  217. [literal]#++/myapp++#.
  218. [source, java]
  219. ----
  220. @SpringUI
  221. ----
  222. See <<advanced.spring.deployment>> for how to handle servlet URL mapping of
  223. Spring UIs when working with multiple servlets in the same web application.
  224. (((range="endofrange", startref="term.advanced.spring.springui")))
  225. [[advanced.spring.scopes]]
  226. == Scopes
  227. ((("Spring", "scopes", id="term.advanced.spring.scopes", range="startofrange")))
  228. As in programming languages, where a variable name refers to a unique object
  229. within the scope of the variable, an object has unique identity within a scope
  230. in Spring. However, instead of identifying the objects by variable names, they
  231. are identified by their type (object class) and any qualifiers they may have.
  232. The scope of an object can be defined with an annotation to the class as
  233. follows:
  234. [source, java]
  235. ----
  236. @VaadinSessionScope
  237. public class User {
  238. ...
  239. ----
  240. Defining a scope in Spring is normally done with the [classname]#@Scope#
  241. annotation. For example, [literal]#++@Scope("prototype")++# creates a new
  242. instance every time one is requested/auto-wired. Such standard scopes can be
  243. used with some limitations. For example, Spring session and request scopes do
  244. not work in background threads and with certain push transport modes.
  245. Vaadin Spring provides three scopes useful in Vaadin applications: a session
  246. scope, a UI scope, a view scope, all defined in the
  247. [package]#com.vaadin.spring.annotation# package.
  248. [[advanced.spring.scopes.session]]
  249. === [classname]#@VaadinSessionScope#
  250. The session scope is the broadest of the custom scopes defined in Vaadin Spring.
  251. Objects in the Vaadin session scope are unique in a user session, and shared
  252. between all UIs open in the session. This is the most basic scope in Vaadin
  253. applications, useful for accessing data for the user associated with the
  254. session. It is also useful when updating UIs from a background thread, as in
  255. those cases the UI access is locked on the session and also data should be in
  256. that scope.
  257. [[advanced.spring.scopes.ui]]
  258. === [classname]#@UIScope#
  259. UI-scoped beans are uniquely identified within a UI instance, that is, a browser
  260. window or tab. The lifecycle of UI-scoped beans is bound between the
  261. initialization and closing of a UI. Whenever you inject a bean, as long as you
  262. are within the same UI, you will get the same instance.
  263. Annotating a Spring view (annotated with [classname]#@SpringView# as described
  264. later) also as [classname]#@UIScoped# makes the view retain the same instance
  265. when the user navigates away and back to the view.
  266. [[advanced.spring.scopes.view]]
  267. === [classname]#@ViewScope#
  268. The annotation enables the view scope in a bean. The lifecycle of such a bean
  269. starts when the user navigates to a view referring to the object and ends when
  270. the user navigates out of the view (or when the UI is closed or expires).
  271. Views themselves are by default view-scoped, so a new instance is created every
  272. time the user navigates to the view.
  273. (((range="endofrange", startref="term.advanced.spring.scopes")))
  274. ifdef::web[]
  275. [[advanced.spring.navigation]]
  276. == View Navigation
  277. Vaadin Spring extends the navigation framework in Vaadin, described in
  278. <<advanced-navigator#advanced.navigator,"Navigating
  279. in an Application">>. It manages Spring views with a special view provider and
  280. enables view scoping. Furthermore, Vaadin Spring provides a customized navigator class
  281. [classname]#SpringNavigator# that supports the scope functionality.
  282. [[advanced.spring.navigation.ui]]
  283. === Preparing the UI
  284. You can define navigation for any single-component container, component container or bean
  285. implementing [classname]#ViewDisplay#, as described in
  286. <<advanced-navigator#advanced.navigator.navigating,"Setting
  287. Up for Navigation">>, but typically you set up navigation for the entire UI
  288. content. The easiest way to set up navigation is to use the annotation
  289. [classname]#@SpringViewDisplay# on the UI (in which case the whole contents of the UI are
  290. replaced on navigation) or on any UI scoped bean implementing one of the above mentioned
  291. interfaces.
  292. [source, java]
  293. ----
  294. @SpringUI(path="/myspringui")
  295. @SpringViewDisplay
  296. public class MySpringUI extends UI {
  297. @Override
  298. protected void init(VaadinRequest request) {
  299. }
  300. }
  301. ----
  302. If not using Spring Boot, auto-configuration of navigation can be enabled with the annotation
  303. @EnableVaadinNavigation on a configuration class.
  304. [[advanced.spring.navigation.view]]
  305. === The View
  306. A view managed by Vaadin Spring only needs to have the [classname]#@SpringView#
  307. annotation, which registers the view in the [classname]#SpringViewProvider#. The
  308. annotation is also necessary to enable Spring features in the view, such as
  309. injection.
  310. [source, java]
  311. ----
  312. @SpringView(name=MainView.NAME)
  313. public class MainView extends CustomComponent implements View {
  314. public static final String NAME = "main";
  315. ...
  316. ----
  317. The annotation can have the following optional paramers:
  318. name (optional):: Specifies the path by which the view can be accessed programmatically and by the
  319. URI fragment.
  320. +
  321. [source, java]
  322. ----
  323. @SpringView(name="main")
  324. ----
  325. +
  326. If the view name is not given, it is derived from the class name by removing a
  327. possible "View" suffix, making it lower case, and using a dash ("-") to separate
  328. words originally denoted by capital letters. Thereby, a view class such as
  329. [classname]#MyFunnyView# would have name " [literal]#++my-funny++#".
  330. +
  331. It is a recommended pattern to have the view name in a static member constant in
  332. the view class, as was done in the example previously, so that the name can be
  333. referred to safely.
  334. +
  335. You can also navigate to a view with a URI fragment such as
  336. [literal]#++#!myview/someparameter++# or programmatically with:
  337. +
  338. [source, java]
  339. ----
  340. getUI().getNavigator().navigateTo("myview/someparameter");
  341. ----
  342. +
  343. The [methodname]#enter()# method of the view gets the URI fragment as parameter
  344. as is and can interpret it in any application-defined way.
  345. uis:: If the application has multiple UIs that use [classname]#SpringViewProvider#,
  346. you can use this parameter to specify which UIs can show the view.
  347. +
  348. [source, java]
  349. ----
  350. @SpringView(name="myview", uis={MySpringUI.class})
  351. ----
  352. +
  353. If the list contains [parameter]#UI.class#, the view is available to all UIs.
  354. +
  355. [source, java]
  356. ----
  357. @SpringView(name="myview", uis={UI.class})
  358. ----
  359. In the following, we have a login view that accesses a session-scoped user
  360. object. Here, we use a constant to define the view name, so that we can use the
  361. constant when navigating to it.
  362. [source, java]
  363. ----
  364. @SpringView(name=LoginView.NAME)
  365. public class LoginView extends CustomComponent
  366. implements View {
  367. public final static String NAME = "";
  368. // Here we inject to the constructor and actually do
  369. // not store the injected object to use it later
  370. @Autowired
  371. public LoginView(User user) {
  372. VerticalLayout layout = new VerticalLayout();
  373. // An input field for editing injected data
  374. BeanItem<User> item = new BeanItem<User>(user);
  375. TextField username = new TextField("User name",
  376. item.getItemProperty("name"));
  377. username.setNullRepresentation("");
  378. layout.addComponent(username);
  379. // Login button (authentication omitted) / Java 8
  380. layout.addComponent(new Button("Login", e ->
  381. getUI().getNavigator().
  382. navigateTo(MainView.VIEWNAME)));
  383. setCompositionRoot(layout);
  384. }
  385. @Override
  386. public void enter(ViewChangeEvent event) {}
  387. }
  388. ----
  389. You could now navigate to the view from any other view in the UI with:
  390. [source, java]
  391. ----
  392. getUI().getNavigator().navigateTo(LoginView.VIEWNAME);
  393. ----
  394. endif::web[]
  395. [[advanced.spring.accesscontrol]]
  396. == Access Control
  397. Access control for views can be implemented by registering beans implementing
  398. [interfacename]#ViewAccessControl# or
  399. [interfacename]#ViewInstanceAccessControl#, which can restrict access to the
  400. view either before or after a view instance is created.
  401. Integration with authorization solutions, such as Spring Security, is provided
  402. by additional unofficial add-ons on top of Vaadin Spring.
  403. [[advanced.spring.accesscontrol.accessdenied]]
  404. === Access Denied View
  405. If access to a view is denied by an access control bean, the access denied view
  406. is shown for it. For non-existing views, the error view is shown. You can set
  407. up an "Access Denied" view that is shown if the access is denied with
  408. [methodname]#setAccessDeniedViewClass()# in [classname]#SpringViewProvider#,
  409. and an error view with [methodname]#setErrorView()# in [classname]#SpringNavigator#.
  410. The same view can also be used both as an access denied view and as an error
  411. view to hide the existence of views the user is not allowed to access.
  412. [source, java]
  413. ----
  414. @Autowired
  415. SpringViewProvider viewProvider;
  416. @Autowired
  417. SpringNavigator navigator;
  418. @Override
  419. protected void init(VaadinRequest request) {
  420. // Set up access denied view
  421. viewProvider.setAccessDeniedViewClass(
  422. MyAccessDeniedView.class);
  423. // Set up error view
  424. navigator.setErrorView(MyErrorView.class);
  425. ----
  426. Note that the error view can also be a class with which an error view bean is
  427. found. In this case, the error view must be UI scoped.
  428. [[advanced.spring.deployment]]
  429. == Deploying Spring UIs and Servlets
  430. Vaadin Spring hooks into Vaadin framework by using a special
  431. [classname]#SpringVaadinServlet#. As described earlier, you do not need to map
  432. an URL path to a UI, as it is handled by Vaadin Spring. However, in the
  433. following, we go through some cases where you need to customize the servlet or
  434. use Spring with non-Spring servlets and UIs in a web application.
  435. [[advanced.spring.servlets.custom]]
  436. === Custom Servlets
  437. When customizing the Vaadin servlet, as outlined in
  438. <<../application/application-lifecycle#application.lifecycle.servlet-service,"Vaadin
  439. Servlet, Portlet, and Service">>, you simply need to extend
  440. [classname]#com.vaadin.spring.server.SpringVaadinServlet# instead of
  441. [classname]#com.vaadin.servlet.VaadinServlet#.
  442. [subs="normal"]
  443. ----
  444. @WebServlet(value = "[replaceable]#/*#", asyncSupported = true)
  445. public class [replaceable]#MySpringServlet# extends SpringVaadinServlet {
  446. }
  447. ----
  448. The custom servlet must not have [classname]#@VaadinServletConfiguration#, as
  449. you would normally with a Vaadin servlet, as described in
  450. <<../application/application-environment#application.environment,"Deploying
  451. an Application">>.
  452. [[advanced.spring.deployment.urlmapping]]
  453. === Defining Servlet Root
  454. Spring UIs are managed by a Spring servlet ( [classname]#SpringVaadinServlet#),
  455. which is by default mapped to the root of the application context. For example,
  456. if the name of a Spring UI is " [literal]#++my-spring-ui++#" and application
  457. context is [literal]#++/myproject++#, the UI would by default have URL "
  458. [literal]#++/myproject/my-spring-ui++#". If you do not want to have the servlet
  459. mapped to context root, you can use a [classname]#@WebServlet# annotation for
  460. the servlet or a [filename]#web.xml# definition to map all Spring UIs to a
  461. sub-path.
  462. For example, if we have a root UI and another:
  463. [subs="normal"]
  464. ----
  465. @SpringUI(path=[replaceable]#""#) // At Spring servlet root
  466. public class [replaceable]#MySpringRootUI# extends UI {...}
  467. @SpringUI("[replaceable]#another#")
  468. public class [replaceable]#AnotherUI# extends UI {...}
  469. ----
  470. Then define a path for the servlet by defining a custom servlet:
  471. [subs="normal"]
  472. ----
  473. @WebServlet(value = "[replaceable]#/myspringuis/*#", asyncSupported = true)
  474. public class [replaceable]#MySpringServlet# extends SpringVaadinServlet {
  475. }
  476. ----
  477. These two UIs would have URLs /myproject/myspringuis and
  478. /myproject/myspringuis/another, respectively.
  479. You can also map the Spring servlet to another URL in servlet definition in
  480. [filename]#web.xml#, as described the following.
  481. [[advanced.spring.servlets.mixing]]
  482. === Mixing With Other Servlets
  483. The [classname]#SpringVaadinServlet# is normally used as the default servlet,
  484. but if you have other servlets in the application, such as for non-Spring UIs,
  485. you need to define the Spring servlet explicitly in the [filename]#web.xml#. You
  486. can map the servlet to any URL path, but perhaps typically, you define it as the
  487. default servlet as follows, and map the other servlets to other URL paths:
  488. [subs="normal"]
  489. ----
  490. &lt;web-app&gt;
  491. ...
  492. &lt;servlet&gt;
  493. &lt;servlet-name&gt;Default&lt;/servlet-name&gt;
  494. &lt;servlet-class&gt;
  495. com.vaadin.spring.server.SpringVaadinServlet
  496. &lt;/servlet-class&gt;
  497. &lt;/servlet&gt;
  498. &lt;servlet-mapping&gt;
  499. &lt;servlet-name&gt;Default&lt;/servlet-name&gt;
  500. &lt;url-pattern&gt;[replaceable]##/myspringuis/*##&lt;/url-pattern&gt;
  501. &lt;/servlet-mapping&gt;
  502. &lt;servlet-mapping&gt;
  503. &lt;servlet-name&gt;Default&lt;/servlet-name&gt;
  504. &lt;url-pattern&gt;/VAADIN/+++*+++&lt;/url-pattern&gt;
  505. &lt;/servlet-mapping&gt;
  506. &lt;/web-app&gt;
  507. ----
  508. With such a setting, paths to Spring UIs would have base path [filename]#/myapp/myspringuis#, to which the (optional) UI path would be appended.
  509. The [filename]#/VAADIN/*# only needs to be mapped to the servlet if there are no other Vaadin servlets.
  510. (((range="endofrange", startref="term.advanced.spring.springlong")))
  511. (((range="endofrange", startref="term.advanced.spring.spring")))