Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Web Application without any XML

Spring JavaConfig makes possible to create spring applications without xml cotext configuration. And servlet 3.0 specification makes possible to create web applications without web.xml.

So, is it possible to create spring web application not using any xml configuration? Is there any already implemented solution?

PS At now I do not see in servlet 3.0 any simple method to use Spring's DispatcherServlet and listener.

like image 393
andrii Avatar asked Dec 11 '09 13:12

andrii


People also ask

Do We Need web xml for Spring boot application?

Spring MVC web applications use the web. xml file as a deployment descriptor file. Also, it defines mappings between URL paths and the servlets in the web. xml file.

Can we create web project without xml?

XML Still Needed Even, with all the features introduced in Servlet 3.0, there are some use cases where we'll still need a web. xml file, among them: We can't define the filter order with annotations – we still need the <filter-mapping> section if we have multiple filters that we need to be applied in a particular order.

Does Spring configuration require xml?

XML is not required for Spring configuration. You can configure Spring with pure Java-based configuration (annotations). For example, instead of using the XML you posted in your question you can create a class with @Configuration and @ComponentScan annotations: @Configuration @ComponentScan(basePackages = {"com.

Is it possible for us to develop a Java web application without using the web xml file?

No, there will be no need of web. xml for servlet based application if you are using servlet version >3.0 and tomcat 7 as it will not run in the previous versions of tomcat. Annotation represents the metadata. If you use annotation, deployment descriptor (web.


1 Answers

Well, don't expect too much support of Spring from Java EE 6 (which is officially out since yesterday) as this won't happen soon in my opinion :) In other words, you'll need to wait for Spring to support Servlet 3.0 to benefit from all facilities. Quoting the Spring Framework 3.0 RC1 released blog post:

* Last but not least, early support for Java EE 6: Spring 3.0 already supports the use of JSF 2.0 and JPA 2.0 in a Spring environment, in addition to JSR-303 and JSR-330 support. Further Java EE 6 related specifications such as Servlet 3.0 will be fully supported as they become available in concrete products; this is scheduled for the Spring 3.1/3.2 timeframe.

So you'll still need XML for now and this should answer your question.

like image 89
Pascal Thivent Avatar answered Sep 28 '22 00:09

Pascal Thivent