2016-07-07 2 views
0

パスを "/"と異なるものに変更すると、404エラーが発生します。その後、私はコンテキストパスを持つ特定の問題があることそれは私には思える/manager/textでコンテキストを混乱させたtomcat7-maven-pluginを展開する

http://localhost:8080/authenticate 404 (Not Found) 

を取得しますが、私は修正する方法がわからない以下のpom.xmlに

<plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><path>/any_word</path><url>http://localhost:8080/manager/text</url> 

を使用する場合、私は、意味しますそれ。私はそのアプリケーションを私のローカルのTomcatで動かすことができましたが、確かに私は同じアプローチを生産に適用することはできません。私はTomcatで見つかった "/"デフォルトを削除しました。それから、 "any_word"を削除し、pom.xmlに "/"を残しました。アプリケーションを完璧に動かすことができますが、サーバー管理者は特定の一意のコンテキストパスを必要とするため、アプリケーションをルートパス "/"に配置することはできません。

私はすべてのステップの下に追加し、私の質問に関連する情報を提供します。私は個人的な観点から重要度の低いものから重要なものへと注文しました(私はpom.xmlで何か問題があると信じていますが、間違っているかもしれないし、Springの設定やTomcat Serverのプロパティを変更しなければなりません)。

前回の起動時に "mvn tomcat7:deploy"の代わりに "mvn clean install tomcat7:run-war"を起動/展開してもブラウザーにはlocalhost:8080/calories-trackerが表示されますTomcatサーバー。

1 - Windowsの

のコマンドプロンプト
C:> mvn tomcat7:deploy 

3 - - プロファイル( "開発")

@Configuration 

@Profile("development") 

@EnableTransactionManagement 

public class DevelopmentConfiguration { 



    @Bean(name = "datasource") 

    public DriverManagerDataSource dataSource() { 



    @Bean(name = "entityManagerFactory") 

    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DriverManagerDataSource dataSource) { 

TomcatManager(http://localhost:8080/manager/html/list

で、私は「/」

2アンデプロイ

4 - catalina.properties

spring.profiles.active=development 

5 - のsettings.xml

<servers> 

     <server> 

       <id>tomcat8</id> 

       <username>admin</username> 

       <password>admin</password> 

     </server> 

    </servers> 

6 - WebAppInitializer

public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 

    @Override 

    protected Class<?>[] getRootConfigClasses() { 

     return new Class<?>[]{RootContextConfig.class, DevelopmentConfiguration.class, TestConfiguration.class, 

       AppSecurityConfig.class}; 

    } 



    @Override 

    protected Class<?>[] getServletConfigClasses() { 

     return new Class<?>[] {ServletContextConfig.class}; 

    } 



    @Override 

    protected String[] getServletMappings() { 

     return new String[]{"/"}; 

    } 

} 

7 - のWeb.xml

<web-app> 

    <display-name>Archetype Created Web Application</display-name> 

    <welcome-file-list> 

     <welcome-file>/resources/calories-tracker.html</welcome-file> 

    </welcome-file-list> 

</web-app> 

8のpom.xml

<build> 

     <finalName>calories-tracker</finalName> 

     <plugins> 

       <plugin> 

        <groupId>org.apache.maven.plugins</groupId> 

        <artifactId>maven-compiler-plugin</artifactId> 

        <version>2.3.2</version> 

        <configuration> 

          <source>${java-version}</source> 

          <target>${java-version}</target> 

        </configuration> 

       </plugin> 





       <plugin> 

        <groupId>org.apache.maven.plugins</groupId> 

        <artifactId>maven-war-plugin</artifactId> 

        <version>2.6</version> 

        <configuration> 

          <failOnMissingWebXml>false</failOnMissingWebXml> 

        </configuration> 

       </plugin> 

       <plugin> 

        <groupId>org.apache.tomcat.maven</groupId> 

        <artifactId>tomcat7-maven-plugin</artifactId> 

        <version>2.2</version> 

        <configuration> 

          <path>/</path> 

          <url>http://localhost:8080/manager/text</url> 

          <server>tomcat8</server> 

          <keystoreFile>${basedir}/other/keystore.jks</keystoreFile> 

          <keystorePass>secret</keystorePass> 

        </configuration> 

       </plugin> 

     </plugins> 

</build> 

***質問を作成した後数分を追加しました 元のプロジェクトはhttps://github.com/jhades/spring-mvc-angularjs-sample-appから下がります。私はTomcatとPomで上記のように変更を加えました。

+0

私はあなたのプロジェクトをクローンし、tomcat7プラグインに '/test'を入れました。アプリケーションがコンテキストパスをテストするためにアプリケーションをデプロイしますが、cssと画像は、アプリケーションがルートパスでそれらを見つけることを期待しているので、うまくいきません。 – Apostolos

+0

Apostolos、どうすればこの問題を解決できますか?アプリケーションのどこで変更する必要がありますか?私はAngularJSに非常に限定されていますが、AngularJSの設定でいくつか変更する必要がありますか? –

+0

私はそれをチェックさせて、私はパスを正しく設定する方法を見つけたら、私は私の答えを投稿します:) – Apostolos

答えて

1

コントローラに$ locationを追加する必要があります。

コンテキストパスをスコープ変数に格納し、指定したコントローラコンテキストでコンテキストパスを使用できます。多分それは一番きれいな方法ではないかもしれませんが、うまくいきます!

編集: は、最初のあなたは、アクション

<link rel="stylesheet" type="text/css" href="/{{path}}/resources/bower_components/pure/pure.css"> 
<link rel="stylesheet" type="text/css" href="/{{path}}/resources/bower_components/pure/grids-responsive.css"> 
<link rel="stylesheet" type="text/css" href="/{{path}}/resources/public/css/pure-theme.css"> 
<link rel="stylesheet" type="text/css" href="/{{path}}/resources//public/css/calories-tracker.css"> 

でそれを見たい場合は、

<script type="text/javascript" data-main="./js/run-loggin-app" 
     src="../bower_components/requirejs/require.js"></script> 

を必要とするために、ログインページに次のタグを変更する必要があるが、これは数ミリ秒かかりますロードするとは、cssのないページがある場合、角度ロードまでインスタンスが表示されることを意味します。

あなたはリンクを相対パスに変更したことを見ることができます。

<link rel="stylesheet" type="text/css" href="../bower_components/pure/pure.css"> 
<link rel="stylesheet" type="text/css" href="../bower_components/pure/grids-responsive.css"> 
<link rel="stylesheet" type="text/css" href="../public/css/pure-theme.css"> 
<link rel="stylesheet" type="text/css" href="../public/css/calories-tracker.css"> 

最初にリンクを変更し、POST/GETエンドポイントを変更してから、スタイリングリンクをどうするかを決めることで開始できます。

+0

Apostolos、私はあなたが非常に良いトリックを提供しているのを見ることができますが、私は少しそれを実装する方法が混乱しています。あなたがHello Worldを指し示すことができるか、あるいはgitからアプリケーションをダウンロードして、正確にどこを変更しなければならないかを指摘できるかどうか尋ねますか?正直なところ、私はサーバにどのように配備したかの問題だと思っていましたが、AngularJsではコンテキストパスを柔軟にするための回避策をコーディングするのが普通です。私はAngularjsで非常に初めからすべてのヒントは高く評価されます。 –

関連する問題