春ブーツにマップしないStruts2のコンベンションプラグイン@Actions

CLD:

使用するために自分のアプリケーションのアップグレード時に春ブーツバージョン2.1.8.RELEASE + Struts2のコアバージョン2.5.20でStruts2の-大会-プラグインのアクションが正しくマッピングされていないと、私はエラーを取得していますが

com.opensymphony.xwork2.config.ConfigurationException:そこにはアクションは、[/]名前空間のマッピングされていないですし、コンテキストパスに関連付けられているアクション名[ホーム] []。

私はアクションをdecalreた場合にはstruts.xml、彼らは完璧に動作します。

以下は私の現在の構成は、なぜ彼らがマッピングされていないのですか?

、私は多くの切り抜いたのconfigsを試してみましたが、何も動いていないようにみえStrutsPrepareAndExecuteFilter春はそれらをスキャンしていないかのように発射ではなく、アクションが、発見されました。これは、依存関係のバージョンの問題だろうか?

application.yaml

  server:
    port: 8080
    servlet:
      context-path: /

Struts2.xml

    <struts>
        <constant name="struts.devMode" value="false" />
        <constant name="struts.convention.action.packages" value="com.myactions.action" />
        <constant name="struts.convention.action.includeJars" value=".*?/myjar.*?jar(!/)?,.*?/myjar*?jar(!/)?" />
        <constant name="struts.objectFactory" value="spring" />
        <constant name="struts.objectFactory.spring.autoWire" value="name" />
        <constant name="struts.multipart.maxSize" value="100000000" />
        <constant name="struts.convention.default.parent.package" value="struts-default"/>

    ## THIS WORKS
    <!--    <package name="home"  extends="struts-default">-->
    <!--        <action name="actionHome" class="com.myactions.action.HomeController" method="actionHome">-->
    <!--            <result name="success">home.jsp</result>-->
    <!--        </action>-->
    <!--    </package>-->

    </struts>

コントローラ

@Namespace("/")
public class HomeController extends BaseController {

    @Action("home")
    public String actionHome() throws Exception {           
        return SUCCESS;
    }   
}

メイン

@SpringBootApplication
@ServletComponentScan
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder springApplicationBuilder) {
        return springApplicationBuilder.sources(Application.class);
    }

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

}

Struts2のフィルター

@WebFilter("/*")
public class Struts2Filter extends StrutsPrepareAndExecuteFilter {

}

更新

依存関係

マルク・タリン:

試行錯誤の数日後に、ここではいくつかの手がかりがあります。

struts.xml作品で構成されたStruts 2.5.20と春ブーツ2.1.8。あなたの挙POMは、少なくとも次の依存関係が必要です。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.1.8</version>
</dependency>
...
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts2.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-spring-plugin</artifactId>
    <version>2.5.20</version>
</dependency>

私はまた、追加することをお勧めコンフィグブラウザのプラグインを簡単に利用可能なアクションをリストします:

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-config-browser-plugin</artifactId>
    <version>2.5.20</version>
</dependency>

あなたがパッケージ化するとき、それは動作します:

struts.xmlを取り除くだけJavaクラスを通して、あなたのアクションを設定するには、条約のプラグインが必要です。

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-convention-plugin</artifactId>
    <version>2.5.20</version>
</dependency>

ノート :

  • struts.xmlで定義された定数もstruts.propertiesファイル(リストされているデフォルト値に移行することができ、ここで
  • struts.xmlは、条約のプラグインとstruts.propertiesに優先します

struts.xmlが除去されると、条約のプラグインが引き継ぎ、Actionクラスは、パッケージとクラスの名前を使用してマッピングされます。デフォルトの規約は、(アクション・ツー・URLマッピング、結果のパス...)ものセットのおかげで上書きすることができ、注釈を

OPによって述べたように、まだ、注釈を介してコンフィギュレーションはないNOT埋め込みのTomcat(それはしかし、外部のTomcatのでない)を有する箱から出して動作します。

ベスト私がこれまで行うことができ、それを使用して動作させるある組み込みのJettyの代わりにTomcatを、そして追加の推奨設定を struts.propertiesに:

struts.convention.exclude.parentClassLoader=false
struts.convention.action.fileProtocols=jar,code-source

ログはまだショーのエラーを開始するが、私はこれ以上のXMLで構成されたアクションにアクセスすることができますよ。

更新

OPの更新の後、私はもう少しで掘っ。これは、次の操作を実行して、条約プラグインはTomcatで罰金埋め込まれており、必要に応じていないXMLを作品判明します:

  • struts.propertiesに次の行を追加します

    struts.convention.exclude.parentClassLoader=false
    
  • アップグレードのasmモジュールには、ASMASM-コモンズASM-ツリー 6.2をリリースするのか、後に同様のエラーを防ぐために

    ERROR org.apache.struts2.convention.DefaultClassFinder.<init>:95 - Unable to read class [...]
    

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=315688&siteId=1