2017-08-09 3 views
0

これは、これは私のプロジェクトのディレクトリ構造スプリングブートアプリケーション。スタータークラスは、.xmlのファイルを見つけることができません

enter image description here

そして、私はそれがこの

を出力するアプリケーションを実行していますです

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

私のスターターアプリケーションクラスであります

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] 

誰でもこの問題を解決できますか?

+2

@ImportResourceアノテーションは、Spring Bean定義ファイル用です。 デプロイメント記述子をインポートしようとしている場合(ファイル "web.xml"という名前から推測します)、Springブートが提供できるTomcat/Jetty/Undertowサーバを使用することをお勧めします。もはやデプロイメント記述子が必要ありません。 http://docs.spring.io/spring-boot/docs/1.5.x/reference/htmlsingle/#boot-features-developing-web-applications – aaguilera

答えて

0

web.xmlをインポートする必要はありません。バネ構成ではないため、デプロイメント記述子です。

からwarサーブレットコンテナにプロジェクトパッケージタイプを変更すると、web.xmlが自動的に取り込まれます。春ブーツで

のpom.xml

- <packaging>jar</packaging> 
+ <packaging>war</packaging> 
0

、あなたの春の設定で 'web.xmlファイル' を記述する必要はありません、あなたは次のように書くことができます。

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

また、Springのオブジェクトを管理するパッケージ内のWebPortalApplication.classをプッシュする必要があります。

+0

を参照してください。親愛なるトムですが、XMLファイルの全スタッフはどうですか。私はmvcから起動するように切り替えました。これらの4つのxmlファイルは、Bean、Interceptor、Contextなどを作成するなど、多くの作業を行います。 –

+0

この質問については、 https://stackoverflow.com/questions/31082981/spring-boot-adding-http-request-interceptorsを参照してください。 または春のブート公式サイト、https://projects.spring.io/spring-boot/。 –

関連する問題