2017-02-16 9 views
1

私はStruts 2アプリケーションをSpring Bootに移行しています。アプリケーションブートクラスの中にStrutsPrepareAndExecuteFilterを定義しました。Struts FilterとTomcatを使ったSpringブート

@SpringBootApplication 
public class ClearApplication extends SpringBootServletInitializer { 

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

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
    return application.sources(ClearApplication.class); 
    } 

    @Bean 
    public FilterRegistrationBean filterRegistrationBean() { 
    Collection<String> urlPatterns = new ArrayList<>(); 
    urlPatterns.add("/*"); 
    FilterRegistrationBean registrationBean = new FilterRegistrationBean(); 
    StrutsPrepareAndExecuteFilter struts = new StrutsPrepareAndExecuteFilter(); 
    registrationBean.setFilter(struts); 
    registrationBean.setName("strutsFilter"); 
    registrationBean.setOrder(1); 
    registrationBean.setUrlPatterns(urlPatterns); 
    return registrationBean; 
    } 
} 

ポンポンのファイル構成は以下で

<groupId>com.study.pack</groupId> 
<artifactId>clear</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 
<name>clear</name> 
<description>Demo project for Spring Boot</description> 

私のアクションクラス1つの単純なStrutsアクションと他のJSONアクション、私は私の地元のTomcat上でアプリケーションを展開しています

@Action(value = "welcome", results = { @Result(name = "success", location = "result.jsp") }) 
public String execute() { 
    return "success"; 
} 

@Action(value = "users", results = { @Result(name = "success", type = "json", params = { "root", "userList" }) }) 
public String users() { 
    userList = new ArrayList<>(); 
    userList.add(new User("Carl", "15", "M")); 
    userList.add(new User("Rick", "30", "M")); 
    userList.add(new User("Michonne", "26", "F")); 
    return "success"; 
} 

を持っていますサーバ。 I私がSTSに(またはMavenのコマンドを使用して)アプリケーションを実行すると、アクションが

http://localhost:8080/clear/welcome

http://localhost:8080/clear/users

にURLにアクセスすることができています。しかし、私は標準ストラットエラーを取得しています上記の同じURLにアクセスするとき

コンテキストパス[]に関連付けられた名前空間[/ clear]とアクション名[users]に対応するアクションはありません。

application.propertiesには、次のプロパティ

server.contextPath=/clear 
server.port=8080 

私はそれが働いて得るために、他の構成をしないのですがありますか?

更新:

ローマ-Cは、私はTomcatのサーバーの起動ログをチェックして、コンテキスト・パスが同じで、提案@として。

外部のTomcatサーバ

[ost-startStop-1] o.a.c.c.C.[.[localhost].[/clear]   : Initializing Spring embedded WebApplicationContext 

組み込みTomcatサーバー

[ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/clear] : Initializing Spring embedded WebApplicationContext 

application.propertiesまだ運

src/main/resources  

フォルダ内にあるん。どういうわけかstrutsの注釈は無視されます。私はデフォルトの春ブーツではGitのhttps://github.com/creativekarma/clear

+0

バラ次の行を持っている必要があり

チェックログメッセージは、あなたがこの問題上の任意の運を持っていましたか?ありがとう。 –

+0

悲しいことに、私はしませんでした。 – Bala

答えて

1

にソースコードを犯した

は、ルートアプリケーションコンテキストに埋め込まれたTomcatを初期化します。したがって、/からアプリケーションにアクセスできます。

URLはアクションマッパーによってアクションにマッピングされます。デフォルトのアクションマッパーの実装は、URLを解析してアクション名と名前空間を抽出するDefaultActionMapperです。コンテキストパスの後の最後のスラッシュの前のパスが名前空間であり、アクション名が残りのパスです。

application.properties

server.contextPath=/clear 
server.port=8080 

彼らはMavenのプロジェクト構造を使用してsrc/main/resourcesに配置されている場合は正常に動作します。

INFO 4496 --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/clear]  : Initializing Spring embedded WebApplicationContext 
+0

両方のTomcatサーバーのログは同じログを読み取り、リソースはresourcesフォルダーにあります。私はこれらの知見を元の答えに更新しました。 – Bala

+0

config-browserページでactions urlを使用できますか? –

+0

チェックボックスをオンにすると、ブラウザの設定ページが表示されます。埋め込みTomcatの場合。名前空間/のアクションはすべて空です。 一方、外部のTomcatの場合は、すべてのアクションが表示されます。 – Bala

関連する問題