0

I'm looking for a way to deploy a maven web application using Spring Framework 4.3.13. Everything is working fine when the jars are included (compile scope). I would like to exclude the jar files using (provided scope). I have Wildfly 9 as my application server and I created the spring framework module. But when I remove the jars the application is not working. No errors thrown! http://localhost:8080/springwebapp1 should display a welcome message, but it's not. It displays Forbidden. I have been searching for an example how to do this and I haven't found one yet! Any help would be greatly appreciated!

This is my configuration: application root

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 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.acs.springmvc</groupId>
  <artifactId>springwebapp1</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>springwebapp1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
            <scope>provided</scope>
        </dependency>    
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>        
  </dependencies>
  <build>
    <finalName>springwebapp1</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>                
                    <outputDirectory>${deploy.dir}</outputDirectory>
                </configuration>
            </plugin>
        </plugins> 
  </build>
  <properties>
    <deploy.dir>C:\javatools\AppServers\wildfly-9.0.1.Final\standalone\deployments</deploy.dir>
    <springframework.version>4.3.13.RELEASE</springframework.version>
  </properties>  
</project>

I created the spring modules in Wildfly, (org.springframework) module.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.springframework">
  <resources>
    <resource-root path="spring-aop-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-aspects-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-beans-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-context-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-context-support-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-core-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-expression-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-instrument-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-instrument-tomcat-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-jdbc-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-jms-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-messaging-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-orm-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-oxm-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-test-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-tx-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-web-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-webmvc-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-webmvc-portlet-4.3.13.RELEASE.jar"/>
    <resource-root path="spring-websocket-4.3.13.RELEASE.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api" export="true"/>
    <module name="javaee.api"/>
    <module name="org.apache.commons.logging"/>
    <module name="org.jboss.vfs"/>
    <module name="org.hibernate"/>
    <module name="javax.el.api" export="true"/>
    <module name="com.sun.xml.bind" export="true"/> 
  </dependencies>
</module>

I also tried adding the jboss-deployment-structure.xml to the war file. (I placed in the WEB-INF) and it's been included.

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.apache.commons.logging"/>
            <module name="org.springframework" slot="main" export="true" meta-inf="export"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

Here the java classes: ApplicationConfig.java

package com.acs.config;

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

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.acs")
public class ApplicationConfig
{

}

ApplicationInitializer.java

package com.acs.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer
{
     @Override
        protected Class<?>[] getRootConfigClasses() {
            return new Class[] { ApplicationConfig.class };
        }

        @Override
        protected Class<?>[] getServletConfigClasses() {
            return null;
        }

        @Override
        protected String[] getServletMappings() {
            return new String[] { "/" };
        }
}

HelloRestController.java

package com.acs.controllers;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.acs.pojos.Message;

@RestController
public class HelloRestController {

    @RequestMapping("/")
    public String welcome() {//Welcome page, non-rest
        return "Welcome to RestTemplate Example.";
    }

    @RequestMapping("/hello/{player}")
    public Message message(@PathVariable String player) {//REST Endpoint.

        Message msg = new Message(player, "Hello " + player);
        return msg;
    }
}
pcguy
  • 13
  • 3
  • What are the server's logs? You should have some when trying to deploy your component – DamCx Dec 14 '17 at 14:28
  • Nothing in the server logs! Let me post some! – pcguy Dec 14 '17 at 14:29
  • `WFLYSRV0010: Deployed "springwebapp1.war" (runtime-name : "springwebapp1.war")` – pcguy Dec 14 '17 at 14:42
  • 1
    Can you turn up the logging on wildfly? Are you sure the dependencies are being loaded correctly? – Taylor Dec 14 '17 at 14:53
  • _I would like to exclude the jar files_? So are these provided by wildfly and same/compatible? – pirho Dec 14 '17 at 14:54
  • @pinto yes. They are provided by the AS – pcguy Dec 14 '17 at 15:00
  • @Taylor Yes logging is on and the dependencies are loaded! – pcguy Dec 14 '17 at 15:01
  • Could you better describe what means _the application is not working_? It seems to deploy ok? What then? What should happen but does not? (pirho aka pinto?) – pirho Dec 14 '17 at 19:32
  • @pirho: Sure! Let me explain: if the jars are included I can do: `http://localhost:8080/springwebapp1` and it will display the Hello message. In the other hand if the jars are not included by provided by the container, it displays page not found! – pcguy Dec 14 '17 at 19:39
  • I suggest you to do some excluding. Drop jars one by one to provided and see on which it starts failing. If it fails already on first, change it back and test few another to see if it is any jar or some specific that causes this. – pirho Dec 14 '17 at 19:50
  • @pirho: Thanks for the reply. I tried that already. I think it has something to do with the ApplicationInitializer class. – pcguy Dec 14 '17 at 20:05

0 Answers0