简体   繁体   中英

HTTP Post method not supported by this URL when deployed to jboss EAP 7.1

I've a REST API, that is deployed on JBoss EAP 7.1. When I hit the URL at

http://localhost:8080/MyApp/group

in postman, it gives "HTTP method POST is not supported by this URL" error with status code 405.

When I deploy this API on embedded tomcat server, it works perfectly fine. Here is my controller

@RestController
public class RequestController {
    
    @Autowired
    private GroupService groupService;
    
    @PostMapping( "/group" )
    public GroupInfo fetchGroupInfo( @RequestBody GroupInfo groupInfo ) {
        
        long groupId = groupInfo.getGroupId();
        return groupService.getGroup( groupId );
        
    }

}

main class

@SpringBootApplication
public class MyApp extends SpringBootServletInitializer {

    /**
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
    
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
        return builder.sources(MyApp.class);
    }
    
}

pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.my.package</groupId>
    <artifactId>MyApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MyApp</name>
    <packaging>war</packaging>
    
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        
    </dependencies>
    
    <build>
        <finalName>MyApp</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

The deployment shows no error messages. However, it does show below warning

 WARN  [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0013: Deployment optumRx-0.0.1-SNAPSHOT.war contains CDI annotations but no bean archive was found (no beans.xml or class with bean defining annotations was present).

And the class files are missing in the deployment folder in jboss. Can you please tell, what am I missing?

About path: construction in pom.xml < finalName> MyApp < / finalName> doesn't says about way in url, it's about name of artifact. Try to use http://localhost:8080/group (without MyApp)

About other: if you want deploy on jboss, you must exclude tomcat in pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions> 
</dependency>

About CDI warning - try to use @ComponentScan(basePackages="your.package") on MyApp class

Looks like I missed the servlet api dependency in my project. After I add that dependency everything is working fine. The embedded Tomcat server have this jar and so, it was not needed when I deployed on Tomcat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM