2017-02-09 2 views
0
私は現在、フロントエンドに分離されたプロジェクト(HTML5、jqueryの、CSS)とバックエンド(Spring4のMVCとに取り組んでいます

java config -no web.xml-ビューを使用してビューを消費するための残りの部分を公開します)。各ビューには、同じ親のpomに依存する独自のpomがあります。春4 Javaの設定は、ローカルホストのホーム・ページを設定し、フロント/バックエンドのために戦争を分離:ポート/ myAppsName/

Project's tree structure

私はバックエンドが正常に動作している私は、後にTomcatの中で7

を展開メインプロジェクト、2つの戦争が生成される(フロントとバックエンド)は、(私はそれをすでにテストしてみたコンパイル私がコンピュータのフォルダからindex.htmlを開いたときに、Tomcatの外部からhtmlを開いても、正常に動作します。しかし、フロントエンドの戦争をtomcatでteバックエンド戦争と共に展開し、 "localhost:8080/myAppsName /"と入力すると、http eror 404がスローされます。私はインデックスページをレンダリングするためにhtmlが見つからないことを理解しています。

frontend tree structure

バックエンドAppConfig.java:

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = "org.fedelaper.spring") 
public class AppConfig { 

    @Bean 
    public ViewResolver internalResourceViewResolver() { 
     InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver(); 
     internalResourceViewResolver.setPrefix("/frontend/"); 
     internalResourceViewResolver.setSuffix(".html"); 
     return internalResourceViewResolver; 
    } 

} 

バックエンドAppInitializer.java:

@SuppressWarnings("unchecked") 
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 

    @SuppressWarnings("rawtypes") 
    @Override 
    protected Class[] getRootConfigClasses() { 
     return new Class[] { AppConfig.class }; 
    } 

    @SuppressWarnings("rawtypes") 
    @Override 
    protected Class[] getServletConfigClasses() { 
     return null; 
    } 

    @Override 
    protected String[] getServletMappings() { 
     return new String[] { "/" }; 
    } 

} 

私は実際には空であるプロジェクトのフロントエンドでのweb.xmlを持っていますか

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

</web-app> 

私の質問は: - ローカルホストを入力するとき、どのように私は私のアプリのデフォルトのホーム・ページであることをindex.htmlに設定する必要があります:8080/myAppsNameを?

答えて

0

ジャスト歓迎ファイルリストを使用してフロントエンド・モジュールのweb.xmlファイルを更新します。

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
</welcome-file-list> 
</web-app> 
+0

はあなたに感謝します! 私は「/index.htmlが」へ「/frontend/index.html」からのindex.htmlを移動させることもなかったです – fedelaper

関連する問題