Issue in deploying spring mvc project on Jboss Fuse - spring-mvc

I have created a sample web application (Spring MVC) project using Maven. I am trying to deploy it on Jboss fuse container however running into one error or other.
I have used spring mvc to create the webapp. The web.xml, dispatcher servlet, controller code and pom.xml have been attached below:
I created a new jboss fuse instance and installed following bundles to support spring mvc functionality
install -s mvn:org.aopalliance/com.springsource.org.aopalliance/1.0.0
features:install spring-dm
To deploy war file i use below command:
install war:mvn:com.proj.myproj.dsp/HelloWeb/0.0.1-SNAPSHOT/war?Web-ContextPath=HelloWeb
The bundle however remains in Installed state. When i try to force restart it I get this error
org.eclipse.jetty.aggregate.jetty-all-server - 8.1.14.v20131031 | FAILED HelloWeb: java.lang.NoSuchMethodError: org.springframework.core.GenericTypeResolver.resolveTypeArguments(Ljava/lang/Class;Ljava/lang/Class;)[Ljava/lang/Class;
java.lang.NoSuchMethodError: org.springframework.core.GenericTypeResolver.resolveTypeArguments(Ljava/lang/Class;Ljava/lang/Class;)[Ljava/lang/Class;
at org.springframework.core.convert.support.GenericConversionService.getRequiredTypeInfo(GenericConversionService.java:260)
Please point me to what mistake I am making here. Code of this project below:
Pom.xml (Snapshot)
<groupId>com.proj.myproj</groupId>
<artifactId>HelloWeb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>HelloWeb Maven Webapp</name>
<url>http://maven.apache.org</url>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-web</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Dispatcher servlet
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.tutorialspoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property na***strong text***me="suffix" value=".jsp" />
</bean>
</beans>
Controller
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;
#Controller
#RequestMapping("/hello")
public class HelloController{
#RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
System.out.println("Request comes to controller");
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
If you need any other details please let me know.

cause of NoSuchMethodError is almost due to conflicting library versions. In this case I'm guessing there are multiple versions of spring libraries. Use osgi:list to list the installed bundles.
hope this helps

Related

Prometheus metrics servlet doesn't show any metrics

I am using resilience4j circuitbreakers and am having trouble exporting the metrics with the prometheus servlet client. I am deploying to a jbossas7 server, but my /metrics endpoint doesn't show anything. Anyone any ideas? I am injecting the circuitbreaker into a bean, which works fine with the circuitbreaker initiation code below, which resides in a factory.
When I debug my code, I see the circuitbreaker being made and registered in the collectorRegistry. But when it is written in the servlet of the simpleclient servlet, nothing is written to the output. It just skips to the finally block in the client library code
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<servlet>
<servlet-name>metrics</servlet-name>
<servlet-class>io.prometheus.client.exporter.MetricsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>metrics</servlet-name>
<url-pattern>/metrics</url-pattern>
</servlet-mapping>
</web-app>
pom.xml dependencies
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-circuitbreaker</artifactId>
<version>${resilience4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-prometheus</artifactId>
<version>0.13.1</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.5.0</version>
</dependency>
circuitbreaker initiation
public CircuitBreaker getInjectedCircuitbreaker(InjectionPoint injectionPoint) {
Circuitbreaker breaker = injectionPoint.getAnnotated().getAnnotation(Circuitbreaker.class);
CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker(breaker.breakerName());
collectorRegistry.register(CircuitBreakerExports.ofCircuitBreakerRegistry(circuitBreakerRegistry));
return circuitBreaker;
}

surefire vs failsafe : proguard issue

I just start working with an existing application where tests are mixed up (unit tests and integration tests) under src/test and i need to sort things out and put right tests at right place.
All are running fine with surefire right now but when trying to move integration test to failsafe, i can't figure out why it is not working.
I am getting this error while performing a select during a bean creation : java.lang.IllegalStateException: Failed to load ApplicationContext
It seems a table is missing in the database.
I can see that whith surefire, there is a step which uses hibernate to clear database and recreate it before running the tests but i can't see it with failsafe.
I don't know where to look up for this step and how to activate it with failsafe.
I am not very familiar with the environment but i know there is :
maven 3.2.5
maven-surefire-plugin 2.19.1
maven-failsafe-plugin 2.19.1
spring framework 4.0.0
Thanks for any suggestion for where to look.
Is there any difference between surefire and failsafe that need to be configured differently from one to another to run the exact same test?
The problem
Trying to create an MCVE, i figured out that the issue is not annotations but proguard-maven-plugin.
The problem can be reproduced with an sql database and a simple maven project with these files :
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>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MCVE</name>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.5.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals><goal>proguard</goal></goals>
</execution>
</executions>
<configuration>
<proguardInclude>${basedir}/obfuscation.config.debug</proguardInclude>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>true</skip>
<includes>
<include>**/*It.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>false</skipTests>
<includes>
<include>**/*It.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
User.java
package myPackage;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "users")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name = "username", nullable = false)
private String username;
public User() {}
public final String getUsername() {
return username;
}
public final void setUsername(final String pUsername) {
username = pUsername;
}
}
UserIt.java
package myPackage;
import org.junit.Test;
import org.springframework.context.ApplicationContextAware;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
#ContextConfiguration({"classpath:/test.xml"})
public class UserIt extends AbstractJUnit4SpringContextTests implements ApplicationContextAware {
#Test
public void myTest() {
System.out.println("MyTestIsOK");
}
}
obfuscation.config.debug
-dontshrink
-dontoptimize
-dontobfuscate
-dontpreverify
-ignorewarnings
-keep class **
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- xmlns:websocket="http://www.springframework.org/schema/websocket" -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"
>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://127.0.0.1:3306/test</value>
</property>
<property name="username">
<value>myUser</value>
</property>
<property name="password">
<value>myPwd</value>
</property>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>myPackage</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
<property name="generateDdl" value="true" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
</props>
</property>
</bean>
</beans>
Running clean integration-test with surefire will create the user table before running the test but not with failsafe.
It is hard to say something specific without having more information (e.g. relevant parts from pom.xml). Here are some general pointers to give some background though:
Maven build lifecycle
A normal Maven build runs through several phases. The relevant phases (with simplified descriptions) for this discussion are:
…
test: runs unit tests
…
(package: build a jar or war file)
pre-integration-test: prepares the environment for integration tests
integration-test: runs integration tests
post-integration-test: shuts down the integration test environment
verify: checks the result from the integration test
…
So Maven is designed to run integration tests in a special environment. An example would be that a Tomcat is set up and started and the projects war file (that was built in the package phase) is deployed on it in the pre-integration-test phase. Than the integration tests are run in the integration-test phase. In the post-integration-test phase the Tomcat is shut down. The test results are collected in the verify phase.
maven-surefire-plugin vs maven-failsafe-plugin
Both plugins belong to the Maven Surefire project.
The maven-surefire-plugin runs unit tests and binds to the test phase by default.
The maven-failsafe-plugin runs integration tests and binds to the integration-test and verify phases by default.
The reason that there are those two different plugins is, that the maven-failsafe-plugin does not fail the build immediately so the post-integration-test phase will run in any case. Only the verify phase fails the build on test failures.
Your problem
In response to your edits 1-3: Are you sure the integration tests include ContextManagerTest? It sounds like the maven-failsafe-plugin does not know about this test class and thus does not execute its #Before method and thus does not initialize the Spring context and thus does not recreate the database using Hibernate.
Try to create a MCVE by removing all irrelevant classes and configurations, only keeping e.g. one unit test, one integration test, the ContextManagerTest (each of which do something stupid like a System.out.println(…)) and the pom.xml.

Failed to detect ServletContainerInitializers for context - Run time error in Spring MVC application

I am creating spring web-mvc application from scratch without using archetype.
Application build successfully but creating but getting run-time exception
I am using Tomcat-7, I have spring-webmvc in classpath. Please check buildpath image below. Need help to understand issue here
SEVERE: Failed to detect ServletContainerInitializers for context with name [/samplerestservice]
java.io.IOException: java.lang.ClassNotFoundException: org.springframework.web.SpringServletContainerInitializer
at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:199)
at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:157)
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1575)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1281)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5479)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.springframework.web.SpringServletContainerInitializer
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1856)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1705)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:196)
... 15 more
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>com.sample.restservice</groupId>
<artifactId>samplerestservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.1.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>restService-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>restService-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
restService-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/conext
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="samplerestservice" />
<mvc:annotation-driven></mvc:annotation-driven>
</beans>
Build Path
Deployment Assembly
Check this error line:
SEVERE: Failed to detect ServletContainerInitializers for context with name [/samplerestservice]
It is expecting some ContainerInitializerObject you define in the code.
Any reason you want to configure all this stuff by hand? The recommended way to get started with Spring these days is to use Spring Boot which auto-configures sensible defaults based on what's in your pom.xml and what's on the classpath. Further manual tweaks to configuration can be done in Java and properties files where necessary. It's cleaner, faster and way less hassle than the traditional way. The spring-boot-web-starter also embeds an instance of tomcat preconfigured to run on port 8080. The spring guys provide an official tool called the SPRING INITIALIZR where you can choose which spring projects to include in your spring-boot application and it gives you a project with all the right stuff in the pom.xml and the correct folder structure. You just need to import it into eclipse using import -> existing maven project. You can get up and running in minutes, not hours or days.
Judging from the issue you created on the Spring issue tracker, SPR-13872, it seems this problem is not strictly related to Spring but may come from something else.
issue was related to spring framework 4.1.9.RELEASE
After updating to 4.0.5.RELEASE Issue resolved

How to install dandelion datatables

I am trying to install dandelion datatables and I have some problems with the configuration
Following the guide here I added the following to my pom
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.github.dandelion</groupId>
<artifactId>datatables-jsp</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.github.dandelion</groupId>
<artifactId>datatables-export-itext</artifactId>
<version>1.1.0</version>
</dependency>
Then I added the following to my web.xml file
<!-- Dandelion servlet definition and mapping -->
<servlet>
<servlet-name>dandelionServlet</servlet-name>
<servlet-class>com.github.dandelion.core.web.DandelionServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dandelionServlet</servlet-name>
<url-pattern>/dandelion-assets/*</url-pattern>
</servlet-mapping>
<!-- Dandelion filter definition and mapping -->
<filter>
<filter-name>dandelionFilter</filter-name>
<filter-class>com.github.dandelion.core.web.DandelionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>dandelionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I am serving the data from a spring mvc controller to my jsp page where I put the following
<%# taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %>
<datatables:table id="myTableId" data="${data}">
<datatables:column title="ID" property="id" />
</datatables:table>
I am using servlet 3.1 (web.xml below)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
My container is tomcat 8
PROBLEM
When the table is populated but css and js file are not reachable. The datatable instead works ok but without styling. The pagination however works.
Below some of the link generated that are not reachable.
http://localhost:8080/dtproject/dandelion/datatables/css/jquery.dataTables.css
http://localhost:8080/dtproject/dandelion/jquery/js/jquery.js
http://localhost:8080/dtproject/dandelion/datatables/js/jquery.dataTables.js
Can anyone help?
Thanks
UPDATE
To tell the engine to load resources from external CDNs I have added the following line to the datatables.properties conf file
asset.locations.resolution.strategy = remote,webapp,webjar,classpath,jar
When I run the program I get this error:
Dandelion: Some properties of your configuration file are not recognized.
The group 'asset' contains 1 unknown property:
I downgraded servlet version from 3.1 to 3.0 and now it works
Life is strange sometime

Spring MVC - Apache CXF: Is there a main() or init() where I can spawn a worker thread on startup?

I am new to Apache CXF and Spring MVC. I would appreciate your help here.
I used Maven (mvn) to download the org.apache.cxf.archetype:cxf-jaxrs-service archetype (Simple CXF JAX-RS webapp service using Spring configuration).
Here are the relevant artefacts and versions in pom.xml:
<properties>
<jackson.version>1.8.6</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
The web service works great. However, I need to spawn a thread on start-up to initialize a process that I would like to run on my web server. Normally I would do so in the main() method of a simple Java application or HttpServlet init().
Can you tell me how I could achieve the same here? This is a simple application, so I would prefer not to use an application server (e.g. JBOSS), Apache Camel, RMI, etc.
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
You should be able to implement a custom ServletContextListener and do your work in the "contextInitialized" method.
https://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html
You register it in your web.xml using the listener-class element. You'll notice that Spring actually bootstraps itself in the same manner using its ContextLoaderListener.

Resources