0
votes

I'm creating multiple web services that will share the same Jar's so i tried placing the Jar' files in glassfish /domain1/lib folder.

If i am using a maven build that adds all my dependecies in my WAR file the application works. However, when a I run the application using the shared lib it fails.

WebModule[null] ServletContext.log():No Spring WebApplicationInitializer types detected on classpath

Here is My 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>xxx.xxx.xxx</groupId>
    <artifactId>xxxx</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>
    <name>XXXX Web Service</name>


    <!-- Properties ===================================================================== -->
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Spring -->
        <spring-framework.version>4.2.0.RELEASE</spring-framework.version>
        <spring-security.version>4.0.2.RELEASE</spring-security.version>

        <!-- Logging -->
        <logback.version>1.1.3</logback.version>
        <slf4j.version>1.7.12</slf4j.version>

        <!-- Web -->
        <servlet.version>3.1.0</servlet.version>

        <!-- Jackson -->
        <jackson.version>2.6.1</jackson.version>

        <!-- Jasypt -->
        <jasypt.version>1.9.2</jasypt.version>

        <!-- Hamcrest -->
        <hamcrest.version>1.3</hamcrest.version>

        <!-- Mockito -->
        <mockito.version>1.10.19</mockito.version>

        <!-- jsonpath -->
        <jsonpath.version>2.0.0</jsonpath.version>

        <!-- Thymeleaf -->
        <thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>

        <!-- Apache Commons Lang -->
        <apache.commons.lang.version>3.4</apache.commons.lang.version>

        <!-- Aspectj -->
        <aspectj.version>1.8.6</aspectj.version>

        <!-- Test -->
        <junit.version>4.11</junit.version>

    </properties>

    <!-- Dependencies =================================================================== -->
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring-framework.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring-framework.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring-framework.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring-framework.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring-framework.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring-framework.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>4.2.0.RELEASE</version>
            <scope>provided</scope>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring-security.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring-security.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring-security.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Thymeleaf -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring4</artifactId>
            <version>${thymeleaf.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Web -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>${jackson.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Jasypt -->
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>${jasypt.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt-spring31</artifactId>
            <version>${jasypt.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- E-Channels Encryptor -->
        <dependency>
            <groupId>xxx.xxx.xxx</groupId>
            <artifactId>xxxxx</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Apache Commons Lang -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${apache.commons.lang.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Aspectj -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring-framework.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <version>${spring-security.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>${jsonpath.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path-assert</artifactId>
            <version>${jsonpath.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>xxxx</finalName>

        <sourceDirectory>src/main/java</sourceDirectory>

        <testSourceDirectory>src/test/java</testSourceDirectory>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.7</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

Here is the list of Jars i placed at the Glassfish domain1\lib

aopalliance-1.0.jar
,aspectjrt-1.8.6.jar
,aspectjweaver-1.8.6.jar
,commons-lang3-3.4.jar
,commons-logging-1.2.jar
,eCh2Utils-1.0.0.jar
,jackson-annotations-2.6.0.jar
,jackson-core-2.6.1.jar
,jackson-databind-2.6.1.jar
,jackson-jaxrs-base-2.6.1.jar
,jackson-jaxrs-json-provider-2.6.1.jar
,jackson-module-jaxb-annotations-2.6.1.jar
,jasypt-1.9.2.jar
,jasypt-spring31-1.9.2.jar
,javassist-3.16.1-GA.jar
,jcl-over-slf4j-1.7.12.jar
,logback-classic-1.1.3.jar
,logback-core-1.1.3.jar
,ognl-3.0.8.jar
,slf4j-api-1.7.12.jar
,spring-aop-4.2.0.RELEASE.jar
,spring-aspects-4.2.0.RELEASE.jar
,spring-beans-4.2.0.RELEASE.jar
,spring-context-4.2.0.RELEASE.jar
,spring-context-support-4.2.0.RELEASE.jar
,spring-core-4.2.0.RELEASE.jar
,spring-expression-4.2.0.RELEASE.jar
,spring-security-config-4.0.2.RELEASE.jar
,spring-security-core-4.0.2.RELEASE.jar
,spring-security-web-4.0.2.RELEASE.jar
,spring-web-4.2.0.RELEASE.jar
,spring-webmvc-4.2.0.RELEASE.jar
,thymeleaf-2.1.4.RELEASE.jar
,thymeleaf-spring4-2.1.4.RELEASE.jar
,unbescape-1.1.0.RELEASE.jar

This the only thing shown to me when I deploy the application

2015-09-11T14:35:08.989+0800|Info: GUI deployment: uploadToTempfile
2015-09-11T14:35:08.989+0800|Info: uploadFileName=xxxx.war
2015-09-11T14:35:09.006+0800|Info: ================== availabilityEnabled  skipped
2015-09-11T14:35:09.380+0800|Info: visiting unvisited references
2015-09-11T14:35:09.422+0800|Info: visiting unvisited references
2015-09-11T14:35:09.498+0800|Info: visiting unvisited references
2015-09-11T14:35:09.899+0800|Info: WebModule[null] ServletContext.log():No Spring WebApplicationInitializer types detected on classpath
2015-09-11T14:35:09.958+0800|Info: Loading application [xxxx] at [/xxxx]
2015-09-11T14:35:10.041+0800|Info: xxxx was successfully deployed in 1,016 milliseconds.

This is our WebAppInitializer code

public class WebAppInitializer extends
        AbstractAnnotationConfigDispatcherServletInitializer {

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.web.servlet.support.
     * AbstractAnnotationConfigDispatcherServletInitializer
     * #getRootConfigClasses()
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { SpringConfig.class, SpringSecurityConfig.class };
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.web.servlet.support.
     * AbstractAnnotationConfigDispatcherServletInitializer
     * #getServletConfigClasses()
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.springframework.web.servlet.support.AbstractDispatcherServletInitializer
     * #getServletMappings()
     */
    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }
}
1
If any of you are wondering still have not gotten this to work. We had to revert back to using a web-xml.Jefrey Valencia
same problem, did you find something ?Mohamed Ramrami
Sorry but no we did not.Jefrey Valencia

1 Answers

-1
votes

This took me an embarrassingly long to solve.... Check out my pom.xml ...

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.outbottle</groupId>
<artifactId>PersonalDetailsMVC</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>PersonalDetailsMVC</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>4.0.1.RELEASE</spring.version>
    <jstl.version>1.2</jstl.version>
    <javax.servlet.version>3.0.1</javax.servlet.version>
</properties>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${javax.servlet.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>${jstl.version}</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Problem was my package name. After checking:

a) Runtime package name in the IDE (Netbeans for me) to see if my runtime source was 1.8kjdk against the POM

b) Double checked the POM (pom.xml) to ensure it has the Javax servlet config for annotations (3.0+) and Spring dependencies

c) Double checked my WebInitializer.java (implements WebApplicationInitializer (instead of web.xml)) was syntaxically correct

d) Double checked my Config.java file to ensure it was correctly overloading addResourceHandlers(ResourceHandlerRegistry registry) and the bean for setupViewResolver() was correct

e) Double checked my folder structure to ensure it was correct and the programatic flow looked coherent

f) Remove and redeployed Glassfish to see if anything would change

then I found my issue which was:

f) "com.trainer.config" is wrong! It MUST be "com.outbottle" (then config/controllers/model/etc) for it to work. As you can see above, I used Maven (for the first time), Spring, 1.8 JDK and nearly had a stroke debugging this issue. All running on Glassfish (Tomcat is ok too for the above pom config). That said, I'm all happy with myself now and know Maven and Spring much better for the next step of my Spring learning curve. Hoping this helps you also!