2017-08-01 22 views
0

Spring mvcアプリケーションを実装してJBossにデプロイし、ブラウザから呼び出せるようにしようとしています。Spring MVCのフルコードリクエストマッピングが見つかりません

私のWebConfig:

package com.heatmanofurioso.concertlivecheck.webapp; 

import org.springframework.web.WebApplicationInitializer; 
import org.springframework.web.context.ContextLoaderListener; 
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 
import org.springframework.web.servlet.DispatcherServlet; 

import javax.servlet.ServletContext; 
import javax.servlet.ServletException; 
import javax.servlet.ServletRegistration; 

public class WebConfig implements WebApplicationInitializer { 

@Override 
public void onStartup(ServletContext servletContext) throws ServletException { 
    //Defining web xml 
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); 
    rootContext.register(SpringApplicationConfig.class); 
    rootContext.setServletContext(servletContext); 

    //Registering servlet 
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(rootContext)); 
    dispatcher.setLoadOnStartup(1); 
    dispatcher.addMapping("/"); 

    servletContext.addListener(new ContextLoaderListener(rootContext)); 
} 
} 

のjboss-web.xmlの

<?xml version="1.0" encoding="UTF-8" ?> 
<jboss-web> 
    <context-root>CLC</context-root> 
</jboss-web> 

ログインコントローラ

package com.heatmanofurioso.concertlivecheck.plugin.controller; 

import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.RestController; 

@RestController 
public class LoginController { 

@RequestMapping(value = "/test", method = RequestMethod.GET) 
public String greeting5(@RequestParam(value = "name", defaultValue = "World1") String name) { 
    return "Test" + name; 
} 
} 

SpringApplicationConfig

package com.heatmanofurioso.concertlivecheck.webapp; 

import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; 
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 

@EnableWebMvc 
@Configuration 
@ComponentScan(basePackages = { 
"com.heatmanofurioso.concertlivecheck", 
"com.heatmanofurioso.concertlivecheck.plugin"}) 
public class SpringApplicationConfig extends WebMvcConfigurerAdapter { 

@Override 
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { 
    configurer.enable(); 
} 
} 

私の春のバージョンが最新の4.xリリースであり、すべては私のメインのポンポンで宣言 私のwebappポンポン

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<packaging>war</packaging> 
<artifactId>webapp</artifactId> 
<version>1.0-SNAPSHOT</version> 

<parent> 
    <groupId>com.heatmanofurioso.concertlivecheck</groupId> 
    <artifactId>ConcertLiveCheck</artifactId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 

<dependencies> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-api</artifactId> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
    </dependency> 
    <!--Project modules--> 
    <dependency> 
     <groupId>com.heatmanofurioso.concertlivecheck</groupId> 
     <artifactId>utils</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.heatmanofurioso.concertlivecheck</groupId> 
     <artifactId>database</artifactId> 
     <type>pom</type> 
    </dependency> 
    <dependency> 
     <groupId>com.heatmanofurioso.concertlivecheck</groupId> 
     <artifactId>service</artifactId> 
     <type>pom</type> 
    </dependency> 
    <dependency> 
     <groupId>com.heatmanofurioso.concertlivecheck</groupId> 
     <artifactId>plugin</artifactId> 
    </dependency> 
</dependencies> 

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <warName>${parent.artifactId}</warName> 
        <outputDirectory>${project.build.directory}/../../../../../deployments/</outputDirectory> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.8</version> 
       <executions> 
        <execution> 
         <id>install</id> 
         <phase>install</phase> 
         <goals> 
          <goal>sources</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

<properties> 
    <maven.compiler.source>${java.version}</maven.compiler.source> 
    <maven.compiler.target>${java.version}</maven.compiler.target> 
</properties> 
</project> 

マイプロジェクト構造: enter image description here

私は、例のJSPファイルを持って、どの私はマップされたルートを入力しようとするときはlocalhostと同様に、8080/CLC :しかし、私のブラウザが見つけ、ローカルホストで読むことができます8080/CLC /テストを 私は404

ルートかもしれないもの上の任意のヒントを得ます私の問題に?

P.S. JBossの出力:またenter image description here

、それが関連するのですが、春バージョンは4.3.10リリースで、JBossが乱暴

アップデートであることを確認していない場合:だから 、私は4.3.7リリースに春のバージョンをダウングレードし、すべてが今、何のアイデアで働いているのですか?私はまた、Mavenをダウングレードする前に、同じ春バージョンですべての単一のコンポーネントをバンドルしていることを認定

+0

うまく働い:dispatcher.addMapping(「/ *」を)。 Dispatcherサーブレットがすべてのリクエストを処理するようにします。 –

+0

'localhost:8080/CLC/test?name = test'はどうですか? – StanislavL

+0

@StanislavLパラメータは、送信されるリクエスト自体とは何の関係もなく、変数はnullになります。または私は間違っていますか?とにかく、ありがとう、私はそれを試してみました。しかし、いいえ:( –

答えて

0

あなたは、アプリケーション名を公開するだけのためにGETリクエストをしようとする必要はありません。

http://localhost:8080/test 

あなたのURLに1つのより多くのレベルを追加したい場合は、あなたがこれを行うことができます:

@RequestMapping(value = "CLC/test", method = RequestMethod.GET) 
public String greeting5(@RequestParam(value = "name", defaultValue = "World1") String name) { 
    return "Test" + name; 
} 
+0

まだ見つかりません。 また、JBossは自分のコンテキストを自分のipの最初の要素にマップしてはいけません。したがって、context = "CLC"、mapping = "test"、path "localhost:8080/CLC/test"? –

+0

あなたのアプリケーションの実行状況を確認できますか? – andreybleme

+0

はい、私のindex.jspは "localhost:8080/CLC"で見つけられます。テキストは "Hello World"に挿入されています。またJBoss ouput –

0

最新の春のセキュリティはスプリングコア4.3.7を使用して、と私は春のコア4.3.10を使用していました。

これらのライブラリは私のjarファイルで競合していました。

私は4.3.7に私の春のコアを格下げし、すべてはあなたがこのてみてもらえ

+0

のプリントを追加しました。同じ問題がありましたが、4.3.9にダウングレードして問題を解決しましたが、何が問題なのですか? – ashkanr

関連する問題