0

This is my starter application class

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
@ImportResource("classpath : web.xml")
public class WebPortalApplication {
    public static void main(String[] args) {
        SpringApplication.run(WebPortalApplication.class, args);
    }
}

this is my project directory structure

enter image description here

And when I am running the application it prints this

Caused by: java.io.FileNotFoundException: class path resource [classpath : web.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]

Can anybody help me in this problem?

Hayk Mkhitaryan
  • 388
  • 9
  • 26
  • 2
    The @ImportResource annotation is for Spring bean definition files. If you are trying to import a deployment descriptor (as I assume from the name of the file "web.xml"), I suggest you use any of the embedded Tomcat/Jetty/Undertow servers that Spring Boot can provide, so you won't need deployment descriptors anymore. Please see http://docs.spring.io/spring-boot/docs/1.5.x/reference/htmlsingle/#boot-features-developing-web-applications – aaguilera Aug 09 '17 at 06:45

2 Answers2

0

You don't need to import web.xml since it is not spring configuration it is a deployment descriptor.

Change project packaging type from jar to war servlet container should pickup your web.xml automatically.

pom.xml

- <packaging>jar</packaging>
+ <packaging>war</packaging>
Bohdan Levchenko
  • 3,411
  • 2
  • 24
  • 28
0

In spring boot,you don't have to write 'web.xml' in your spring configuration,you can write like this:

@SpringBootApplication
public class WebPortalApplication{
    public static void main(String[] args) {
        SpringApplication.run(WebPortalApplication.class, args);
    }
}

And you should push your WebPortalApplication.class in the package that you want to manger object of Spring.

Tom
  • 19
  • 1
  • Ok Dear Tom, but what about the all staff in xml files. I switched from mvc to boot, and those 4 xml files do much work: create beans, intercepters, context etc. Now how to do so that all those actions perform its task? – Hayk Mkhitaryan Aug 10 '17 at 13:55
  • Well,about this question, you can refer to this link: https://stackoverflow.com/questions/31082981/spring-boot-adding-http-request-interceptors. or spring boot official site,https://projects.spring.io/spring-boot/. – Tom Aug 21 '17 at 07:20