wildfly 12 and spring java config, not working , 403 error - spring

I am trying since few hours to bring this simple application to work on wildfly 12, which was working fine on tomcat. Any how below is log and config
Webappinitializer
#Configuration
public class ListenerConfig implements WebApplicationInitializer{
#Override
public void onStartup(final ServletContext servletContext) throws ServletException {
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.setServletContext(servletContext);
root.scan("com.app");
root.refresh();
final Dynamic servlet = servletContext.addServlet("spring", new DispatcherServlet(root));
servlet.setLoadOnStartup(1);
servlet.addMapping("/*");
servletContext.addListener(new ContextLoaderListener(root));
}
ApplicationConfig
#Configuration
#ComponentScan(basePackages = "com.app")
#PropertySource(value = { "classpath:jdbc.properties" })
#EnableTransactionManagement
public class ApplicationConfig {
MVCConfig
#Configuration
#EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter{
#Override
public void configureMessageConverters( List<HttpMessageConverter<?>> converters ) {
converters.add(converter());
}
#Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
#Bean
public UrlBasedViewResolver setupViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setPrefix("/html/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.servlet.api"/>
<module name="org.apache.log4j"/>
<module name="pluto.lib" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Note I haven't provided complete code, if required will post it.
Finally what I get in log is below
22:36:39,374 INFO [org.jboss.as.connector.subsystems.datasources]
(MSC service thread 1-2) WFLYJCA0001: Bound data source
[java:jboss/datasources/ExampleDS] 22:36:40,290 INFO
[org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0006:
Undertow HTTPS listener https listening on 127.0.0.1:8443 22:36:40,504
INFO [org.jboss.ws.common.management] (MSC service thread 1-3)
JBWS022052: Starting JBossWS 5.2.0.Final (Apache CXF 3.2.2)
22:36:43,005 INFO [org.infinispan.factories.GlobalComponentRegistry]
(MSC service thread 1-4) ISPN000128: Infinispan version: Infinispan
'Bastille' 9.1.6.Final 22:36:43,650 INFO
[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62)
WFLYCLINF0002: Started client-mappings cache from ejb container
22:36:44,314 INFO [org.wildfly.extension.undertow] (ServerService
Thread Pool -- 64) WFLYUT0021: Registered web context: '/Pluto' for
server 'default-server' 22:36:44,412 INFO [org.jboss.as.server]
(ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "Pluto.war"
(runtime-name : "Pluto.war") 22:36:44,857 INFO [org.jboss.as.server]
(Controller Boot Thread) WFLYSRV0212: Resuming server 22:36:44,863
INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http
management interface listening on http://127.0.0.1:9990/management
22:36:44,863 INFO [org.jboss.as] (Controller Boot Thread)
WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
Pluto.war is application and I get 403 forbidden, I have tried multiple things, What I feel is Jboss is not able to pick dispatcher servlet at all, I have used spring with jboss as 7.1, but then it was xml config, I do not use maven so no pom.xml here, this same config is running fine in tomcat 8.
After removing custom lib and placed all the libs in web-inf/lib folder and deleted jboss-deployment-structure.xml from web-inf then its working fine. What wrong am I doing, in case of custom module? I created pluto.lib.main under modules folder and added this in standalone.xml
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<global-modules>
<module name="pluto.lib" slot="main"/>
</global-modules>
Then I am facing 403 error

After a long pain-full debugging along with trial and error with different versions of spring and wild fly, I have come to a conclusion that my custom module which consists of spring 4.3 is not running on wildfly 12.
Anyhow the solution was to downgrade app server to wildfly 11. The very same module and .war runs smoothly on ver 11.
I enabled debug logs on ver 12, still there nothing in logs that could probably show the root cause, I think there is some bug associated to wildfy version 12 and spring.
As of now this seems to work fine, if anyone who is able to find solution for spring with java config on wildfly 12, please post an answer :)

Related

Wildfly 21: bootable JAR can't find H2 JDBC driver/datasource classes

I'm deploying a bootable JAR on Wildfly 21.0.1.Final. The JAR is built with the wildfly-jar-maven-plugin. Here is the plugin configuration:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-jar-maven-plugin</artifactId>
<configuration>
<feature-pack-location>wildfly#maven(org.jboss.universe:community-universe)#21.0.0.Final
</feature-pack-location>
<layers>
<layer>jaxrs-server</layer>
<layer>management</layer>
<layer>observability</layer>
<layer>microprofile-openapi</layer>
<layer>h2-driver</layer>
<layer>h2-datasource</layer>
</layers>
<excluded-layers>
<layer>deployment-scanner</layer>
</excluded-layers>
</configuration>
...
</plugin>
Running the bootable JAR I get the exception below:
java -jar -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0 -Djboss.http.port=8080 -Djboss.management.http.port=9990 customers/target/customers-bootable.jar
14:04:58,500 INFO [org.wildfly.jar] (main) WFLYJAR0007: Installed server and application in /tmp/wildfly-bootable-server15172013110481762654, took 1035ms
14:04:58,607 INFO [org.wildfly.jar] (main) WFLYJAR0008: Server options: [--read-only-server-config=standalone.xml]
14:04:58,653 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.12.Final
14:04:58,658 INFO [org.jboss.threads] (main) JBoss Threads version 2.4.0.Final
14:04:58,730 INFO [org.jboss.as] (MSC service thread 1-1) WFLYSRV0049: WildFly Full 21.0.0.Final (WildFly Core 13.0.1.Final) starting
14:04:59,134 INFO [org.wildfly.security] (ServerService Thread Pool -- 14) ELY00001: WildFly Elytron version 1.13.1.Final
14:04:59,476 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
14:04:59,487 INFO [org.xnio] (MSC service thread 1-2) XNIO version 3.8.2.Final
14:04:59,493 INFO [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.8.2.Final
14:04:59,504 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) WFLYCLINF0001: Activating Infinispan subsystem.
14:04:59,514 INFO [org.wildfly.extension.microprofile.config.smallrye._private] (ServerService Thread Pool -- 37) WFLYCONF0001: Activating WildFly MicroProfile Config Subsystem
14:04:59,516 INFO [org.jboss.as.jaxrs] (ServerService Thread Pool -- 33) WFLYRS0016: RESTEasy version 3.13.2.Final
14:04:59,517 INFO [org.jboss.as.connector] (MSC service thread 1-3) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.4.23.Final)
14:04:59,521 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 42) WFLYNAM0001: Activating Naming Subsystem
14:04:59,519 INFO [org.wildfly.extension.microprofile.openapi.smallrye] (ServerService Thread Pool -- 40) WFLYMPOAI0001: Activating Eclipse MicroProfile OpenAPI Subsystem
14:04:59,522 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 32) WFLYIO001: Worker 'default' has auto-configured to 24 IO threads with 192 max task threads based on your 12 available processors
14:04:59,520 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 45) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique.
14:04:59,524 INFO [org.wildfly.extension.microprofile.health.smallrye] (ServerService Thread Pool -- 38) WFLYHEALTH0001: Activating Eclipse MicroProfile Health Subsystem
14:04:59,521 INFO [org.wildfly.extension.microprofile.opentracing] (ServerService Thread Pool -- 41) WFLYTRACEXT0001: Activating MicroProfile OpenTracing Subsystem
14:04:59,537 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
14:04:59,542 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = h2
14:04:59,545 INFO [org.jboss.as.naming] (MSC service thread 1-7) WFLYNAM0003: Starting Naming Service
14:04:59,546 INFO [org.wildfly.extension.microprofile.metrics.smallrye] (ServerService Thread Pool -- 39) WFLYMETRICS0001: Activating Eclipse MicroProfile Metrics Subsystem
14:04:59,549 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0003: Undertow 2.2.2.Final starting
14:04:59,555 INFO [org.jboss.remoting] (MSC service thread 1-3) JBoss Remoting version 5.0.19.Final
14:04:59,611 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0012: Started server default-server.
14:04:59,612 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0018: Host default-host starting
14:04:59,635 WARN [org.jboss.as.domain.http.api.undertow] (MSC service thread 1-3) WFLYDMHTTP0003: Unable to load console module for slot main, disabling console
14:04:59,641 INFO [org.jboss.as.patching] (MSC service thread 1-6) WFLYPAT0050: WildFly Full cumulative patch ID is: base, one-off patches include: none
14:04:59,646 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on [0:0:0:0:0:0:0:0]:8080
14:04:59,654 WARN [org.jboss.as.domain.management.security] (MSC service thread 1-5) WFLYDM0111: Keystore /tmp/wildfly-bootable-server15172013110481762654/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
14:04:59,662 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "customers.war" (runtime-name: "ROOT.war")
14:04:59,743 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
14:05:01,202 INFO [org.jboss.as.jpa] (MSC service thread 1-5) WFLYJPA0002: Read persistence.xml for customers
14:05:01,324 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0003: Processing weld deployment ROOT.war
14:05:01,536 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 6.0.21.Final
14:05:01,706 INFO [io.jaegertracing.internal.JaegerTracer] (MSC service thread 1-1) No shutdown hook registered: Please call close() manually on application shutdown.
14:05:01,721 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."ROOT.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."ROOT.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "ROOT.war"
...
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: org.h2.jdbcx.JdbcDataSource from [Module "deployment.ROOT.war" from Service Module Loader]
The class org.h2.jdbcx.JdbcDataSource isn't found obviously. However, looking in the bootable JAR I see that in the modules directory:
[![modules][1]][1]
So, as shown above, the modules directory contains a module named "com.h2database.h2" and here is the content of the associated module.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<module name="com.h2database.h2" xmlns="urn:jboss:module:1.5">
<resources>
<resource-root path="h2-1.4.197.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
And here is the content of the h2-1.4.197.jar archive:
[![h2][2]][2]
Accordingly, the Wildfly server has a module named "com.h2database.h2" containing the required "org.h2.jdbcx.JdbcDtaSource" class.
So why does the CNFE is raised ? Last but not least, here is the datasource definition:
#Singleton
#DataSourceDefinition(
name = "java:jboss/datasources/ExampleDS",
className = "org.h2.jdbcx.JdbcDataSource",
url = "jdbc:h2:mem:customers",
user = "sa",
password = "sa",
databaseName = "customers")
public class DatasourceProducer
{
#Resource(lookup = "java:jboss/datasources/ExampleDS")
private DataSource ds;
#Produces
public DataSource getDatasource()
{
return ds;
}
}
And the persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="customers" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<properties>
<property name="wildfly.jpa.twophasebootstrap" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle12cDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
Could someone please shed some light here on this issue as I'm stuck since a couple of days :-(
Many thanks in advance.
Kind regards,
Seymour
[1]: https://i.stack.imgur.com/fUBOc.png
[2]: https://i.stack.imgur.com/mHaGb.png
Answering my own question.
It appears that simply defining the h2 dependency as follows:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
instead of:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
solves the problem.

AspectJ LTW (weaving) not working with Spring Boot

I'm on Spring Boot 2.1.2.RELEASE - Java 11 - Fat JAR
Following the documentation, I have:
added the required dependencies to the Gradle build
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.aspectj:aspectjrt:1.9.2'
implementation 'org.aspectj:aspectjweaver:1.9.2'
enabled LoadTimeWeaving
#SpringBootApplication
#EnableLoadTimeWeaving
public class MyApplication { ... }
provided the aop.xml under META-INF
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver>
<!-- only weave classes in our application-specific packages -->
<include within="my.base.package.*" />
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="my.base.package.spring.aop.MyAspects" />
</aspects>
</aspectj>
created the new #Aspect class
#Aspect
public class MyAspects {
#Around("methodsToBeProfiled()")
public Object profile(final ProceedingJoinPoint pjp) throws Throwable {
final var sw = new StopWatch(getClass().getSimpleName());
try {
sw.start(pjp.getSignature().getName());
return pjp.proceed();
} finally {
sw.stop();
System.out.println(sw.prettyPrint());
}
}
#Pointcut("execution(* my.base.package.other.MyClass.*(..))")
public void methodsToBeProfiled() {}
}
added the Jar for instrumentation
-javaagent:/home/myuser/spring-instrument-5.1.5.RELEASE.jar
Log, which as you see, show MyAspects as recognized
[AppClassLoader#2c13da15] info AspectJ Weaver Version 1.9.2 built on Wednesday Oct 24, 2018 at 15:43:33 GMT
[AppClassLoader#2c13da15] info register classloader jdk.internal.loader.ClassLoaders$AppClassLoader#2c13da15
[AppClassLoader#2c13da15] info using configuration /home/edoardo/IdeaProjects/scheduler/scheduler-engine/out/production/resources/META-INF/aop.xml
[AppClassLoader#2c13da15] info using configuration file:/home/edoardo/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aspects/5.1.5.RELEASE/3bb95e05b646ef93e2a4cf0b600924c2979fc723/spring-aspects-5.1.5.RELEASE.jar!/META-INF/aop.xml
[AppClassLoader#2c13da15] info register aspect my.base.package.spring.aop.MyAspects
[AppClassLoader#2c13da15] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
[AppClassLoader#2c13da15] info register aspect org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect
[AppClassLoader#2c13da15] info register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect
[AppClassLoader#2c13da15] info register aspect org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect
[AppClassLoader#2c13da15] info deactivating aspect 'org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect' as it requires type 'javax.transaction.Transactional' which cannot be found on the classpath
[AppClassLoader#2c13da15] info register aspect org.springframework.cache.aspectj.AnnotationCacheAspect
[AppClassLoader#2c13da15] info register aspect org.springframework.cache.aspectj.JCacheCacheAspect
[AppClassLoader#2c13da15] info deactivating aspect 'org.springframework.cache.aspectj.JCacheCacheAspect' as it requires type 'org.springframework.cache.jcache.interceptor.JCacheAspectSupport' which cannot be found on the classpath
[AppClassLoader#2c13da15] info deactivating aspect 'org.springframework.cache.aspectj.JCacheCacheAspect' as it requires type 'javax.cache.annotation.CacheResult' which cannot be found on the classpath
[AppClassLoader#2c13da15] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
However MyAspects is never instantiated (so no debug), and methods are not being weaved with my aspect code.
Did I miss something?
Edit: seems both Jars, aspectjweaver and spring-instrument are required as agents. Is this normal?
You do need the aspectjweaver agent jar. You don't need spring-instrument (ever for a fat jar - AFAIK it was used in app servers to work around some historical issues with their class loaders). You also don't need to #EnableLoadTimeWeaving (also an app server feature, redundant if you control the agent). Also (minor niggle) aspectjrt is a transitive dependency of aspectjweaver, so you don't need both. So you have it working it seems, even though you have done more work than you needed. Sample Spring Boot apps with various weaving options: here.

Spring Boot Does Not Seem to Start

I am trying to get a Spring Boot WAR to deploy to a private Tomcat 7.0.68 instance hosted by DailyRazor. I cannot figure out why the Spring Boot application will not work. I do not seem to get any errors. Locally, I have gotten this to work with STS 3.8.4, Tomcat 7.0.78, Tomcat 8.5.11, and a couple other versions of Tomcat.
I never see the Spring Boot banner display on the DailyRazor instance nor much of the other logging indicating that my Spring Boot application is starting and loading all of the beans. This is the only logging I see:
INFO main org.apache.catalina.core.StandardService - Stopping service Catalina
INFO main org.apache.catalina.core.AprLifecycleListener - The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/tomcat/users/user_id/jdk/jre/lib/amd64/server:/usr/local/tomcat/users/user_id/jdk/jre/lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
INFO main org.apache.catalina.startup.Catalina - Initialization processed in 2299 ms
INFO main org.apache.catalina.core.StandardService - Starting service Catalina
INFO main org.apache.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/7.0.68
INFO foobar.com-startStop-1 org.apache.catalina.startup.TldConfig - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
INFO foobar.com-startStop-1 org.apache.catalina.util.SessionIdGeneratorBase - Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [271] milliseconds.
INFO foobar.com-startStop-1 org.apache.catalina.startup.HostConfig - Deploying web application archive /home/user_id/tomcat/webapps/foobar.com/ROOT.war
INFO foobar.com-startStop-1 org.apache.catalina.startup.TldConfig - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
INFO foobar.com-startStop-1 org.apache.catalina.startup.HostConfig - Deployment of web application archive /home/user_id/tomcat/webapps/foobar.com/ROOT.war has finished in 1,603 ms
INFO foobar.com-startStop-1 org.apache.catalina.startup.HostConfig - Deploying web application archive /home/user_id/tomcat/webapps/foobar.com/plant-service-0.0.1-SNAPSHOT.war
INFO foobar.com-startStop-1 org.apache.catalina.startup.TldConfig - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
INFO foobar.com-startStop-1 org.apache.catalina.core.ContainerBase.[Catalina].[foobar.com].[/plant-service-0.0.1-SNAPSHOT] - 3 Spring WebApplicationInitializers detected on classpath
INFO foobar.com-startStop-1 org.apache.catalina.core.ContainerBase.[Catalina].[foobar.com].[/plant-service-0.0.1-SNAPSHOT] - Initializing Spring embedded WebApplicationContext
INFO foobar.com-startStop-1 org.apache.catalina.startup.HostConfig - Deployment of web application archive /home/user_id/tomcat/webapps/foobar.com/plant-service-0.0.1-SNAPSHOT.war has finished in 21,769 ms
INFO main org.apache.catalina.startup.Catalina - Server startup in 26534 ms
INFO ajp-bio-127.0.0.1-9592-exec-1 org.apache.catalina.core.ContainerBase.[Catalina].[foobar.com].[/plant-service-0.0.1-SNAPSHOT] - Initializing Spring FrameworkServlet 'dispatcherServlet'
I have following the instructions for packaging as a WAR, extending SpringBootServletInitializer, overriding configure(...), etc. Again, this all works locally on multiple versions of Tomcat. I have tried to adjust the logging, but I do not see anything useful.
Any hints? Suggestions?
EDIT
Not sure if it is related, but when shutting down Tomcat, I see the following:
INFO main org.apache.catalina.core.StandardService - Stopping service Catalina
ERROR foobar.com-startStop-2 org.apache.catalina.loader.WebappClassLoaderBase - The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
INFO foobar.com-startStop-2 org.apache.catalina.core.ContainerBase.[Catalina].[foobar.com].[/plant-service-0.0.1-SNAPSHOT] - Destroying Spring FrameworkServlet 'dispatcherServlet'
INFO foobar.com-startStop-2 org.apache.catalina.core.ContainerBase.[Catalina].[foobar.com].[/plant-service-0.0.1-SNAPSHOT] - Closing Spring root WebApplicationContext
ERROR foobar.com-startStop-2 org.apache.catalina.loader.WebappClassLoaderBase - The web application [/plant-service-0.0.1-SNAPSHOT] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
ERROR foobar.com-startStop-2 org.apache.catalina.loader.WebappClassLoaderBase - The web application [/plant-service-0.0.1-SNAPSHOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Could you please ensure you did all of this correctly ?
From Create a deployable war file (Spring boot documentation) :
Create a deployable war file
The first step in producing a deployable war file is to provide a
SpringBootServletInitializer subclass and override its configure
method. This makes use of Spring Framework’s Servlet 3.0 support and
allows you to configure your application when it’s launched by the
servlet container. Typically, you update your application’s main class
to extend SpringBootServletInitializer:
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
The next step is to update your build configuration so that your
project produces a war file rather than a jar file. If you’re using
Maven and using spring-boot-starter-parent (which configures Maven’s
war plugin for you) all you need to do is to modify pom.xml to
change the packaging to war:
<packaging>war</packaging>
EDIT
Do you have spring-boot-starter-web and spring-boot-starter-tomcat dependencies ?
To build a war file that is both executable and deployable into an
external container you need to mark the embedded container
dependencies as “provided”, e.g:
<?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">
<!-- ... -->
<packaging>war</packaging>
<!-- ... -->
<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>
<!-- ... -->
</dependencies>
</project>

Wildfly not starting a deployable war file

I have a Spring Boot application that uses Spring Integration to do some SFTP polling...
I am trying to follow this guide to package a jar file and deploy it as a war file to a wildfly 8.2 application server. I am using a gradle plugin that only allows the deploy of war or ear files.
So in my attempt to have this done I run locally with embedded tomcat, and it works flawlessly, but when I test it remotely then the app is deployed but never started.
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Stasher extends SpringBootServletInitializer implements WebApplicationInitializer {
private static Class<Stasher> applicationClass = Stasher.class;
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
public static void main(String[] args) {
System.out.println("MAIN STARTED ***************************");
SpringApplication.run(Stasher.class, args);
}
}
Logs from Wildfly 8.2
19:12:35,347 INFO [org.springframework.jmx.export.annotation.AnnotationMBeanExporter] (MSC service thread 1-4) Registering beans for JMX exposure on startup
19:12:35,352 INFO [org.springframework.context.support.DefaultLifecycleProcessor] (MSC service thread 1-4) Starting beans in phase -2147483648
19:12:35,353 INFO [org.springframework.context.support.DefaultLifecycleProcessor] (MSC service thread 1-4) Starting beans in phase 0
19:12:35,353 INFO [org.springframework.integration.endpoint.EventDrivenConsumer] (MSC service thread 1-4) Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
19:12:35,353 INFO [org.springframework.integration.channel.PublishSubscribeChannel] (MSC service thread 1-4) Channel 'Stasher-Default.errorChannel' has 1 subscriber(s).
19:12:35,353 INFO [org.springframework.integration.endpoint.EventDrivenConsumer] (MSC service thread 1-4) started _org.springframework.integration.errorLogger
19:12:35,359 INFO [org.springframework.boot.SpringApplication] (MSC service thread 1-4) Started application in 1.695 seconds (JVM running for 11619.131)
19:12:35,361 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017534: Registered web context: /Stasher
19:12:35,439 INFO [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "Stasher.war" (runtime-name : "Stasher.war")
Why is the main not starting when in Wildfly?!
It's the configure method that's used when launching a Spring Boot app in an app server. The main method is only used when you launch the app as an executable archive using java -jar.
I removed the extentions of SpringBootServletInitializer, my main and co nfigure methods and added this method instead. It now starts up.
#Override
public void onStartup(ServletContext container) {
ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/applicationContext.xml");
PollableChannel ftpChannel = context.getBean("ftpChannel", PollableChannel.class);
Message<?> message = ftpChannel.receive();
System.out.println("Received message: " + message);
}

DataNucleus auto create table

I have maven multi-module project with Spring 4, DataNucleus 4, and Postgres 9 on JBoss Wildfly.
I want configure their for work together.
But now DataNucleus do not auto create table on databases.
Here my pom of "persistance" maven module :
<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">
<parent>
<artifactId>somem</artifactId>
<groupId>somem</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>persistence</artifactId>
<packaging>jar</packaging>
<name>persistence</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>4.0.5</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>4.0.7</version>
</dependency>
<dependency>
<artifactId>spring-orm</artifactId>
<groupId>org.springframework</groupId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1102-jdbc41</version>
</dependency>
</dependencies>
</project>
this is a User entity :
#PersistenceCapable
public class User {
#PrimaryKey
#Persistent( valueStrategy = IdGeneratorStrategy.IDENTITY )
private Long id;
#Persistent
private String name;
public User() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
my JDOConfigure with Spring
#Configuration
#EnableTransactionManagement
public class JDOConfiguration{
#Bean
public PersistenceManagerFactory persistenceManagerFactory() {
PersistenceManagerFactory persistenceManagerFactory = JDOHelper.getPersistenceManagerFactory("jdo.properties");
return persistenceManagerFactory;
}
#Bean
public JdoTransactionManager JdoTransactionManager() {
JdoTransactionManager JdoTransactionManager = new JdoTransactionManager();
JdoTransactionManager.setPersistenceManagerFactory(persistenceManagerFactory());
return JdoTransactionManager;
}
}
and jdo.properties as config for PersistenceManagerFactory :
datanucleus.autoCreateSchema=true
javax.jdo.PersistenceManagerFactoryClass=org.datanucleus.api.jdo.JDOPersistenceManagerFactory
javax.jdo.option.ConnectionURL= jdbc:postgresql://localhost/somem
javax.jdo.option.ConnectionUserName = dom
javax.jdo.option.ConnectionPassword = dom
javax.jdo.option.ConnectionDriverName = org.postgresql.Driver
Why datanucleus don't create a User table on database?
My output :
/usr/lib/jvm/oracle/jdk1.7.0_21/bin/java -classpath /home/user/software/idea-IU-139.659.2/lib/idea_rt.jar:/home/user/software/idea-IU-139.659.2/lib/util.jar -Dfile.encoding=UTF-8 com.intellij.rt.execution.CommandLineWrapper /tmp/classpath0.tmp com.intellij.javaee.oss.process.JavaeeProcess 37134 com.intellij.javaee.oss.jboss.agent.JBoss71Agent
/home/user/software/wildfly-8.2.0.Final/bin/standalone.sh
[2015-02-06 03:23:19,788] Artifact admin:war: Server is not connected. Deploy is not available.
=========================================================================
[2015-02-06 03:23:19,789] Artifact web:war: Server is not connected. Deploy is not available.
Detected server admin port: 9990
JBoss Bootstrap Environment
Detected server http port: 8080
JBOSS_HOME: /home/user/software/wildfly-8.2.0.Final
JAVA: /usr/lib/jvm/oracle/jdk1.7.0_21/bin/java
JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
=========================================================================
[0m03:23:18,776 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.3.Final
[0m[0m03:23:19,437 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.2.Final
[0m[0m03:23:19,640 INFO [org.jboss.as] (MSC service thread 1-7) JBAS015899: WildFly 8.2.0.Final "Tweek" starting
[0m[0m03:23:21,824 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
[0m[0m03:23:21,854 INFO [org.xnio] (MSC service thread 1-1) XNIO version 3.3.0.Final
[0m[0m03:23:21,881 INFO [org.xnio.nio] (MSC service thread 1-1) XNIO NIO Implementation Version 3.3.0.Final
[0m[0m03:23:21,918 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 31) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
[0m[0m03:23:21,922 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 32) JBAS010280: Activating Infinispan subsystem.
[0m[0m03:23:21,965 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 38) JBAS012615: Activated the following JSF Implementations: [main]
[0m[0m03:23:21,982 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 40) JBAS011800: Activating Naming Subsystem
[0m[0m03:23:21,985 INFO [org.jboss.as.security] (ServerService Thread Pool -- 45) JBAS013171: Activating Security Subsystem
[0m[0m03:23:21,988 INFO [org.jboss.as.security] (MSC service thread 1-4) JBAS013170: Current PicketBox version=4.0.21.Final
[0m[0m03:23:21,999 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
[0m[33m03:23:22,016 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 46) JBAS010153: Node identifier property is set to the default value. Please make sure it is unique.
[0m[0m03:23:22,027 INFO [org.jboss.as.connector.logging] (MSC service thread 1-7) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.9.Final)
[0m[0m03:23:22,051 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS017502: Undertow 1.1.0.Final starting
[0m[0m03:23:22,051 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017502: Undertow 1.1.0.Final starting
[0m[0m03:23:22,061 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010417: Started Driver service with driver-name = h2
[0m[0m03:23:22,070 INFO [org.jboss.as.naming] (MSC service thread 1-8) JBAS011802: Starting Naming Service
[0m[0m03:23:22,071 INFO [org.jboss.as.mail.extension] (MSC service thread 1-8) JBAS015400: Bound mail session [java:jboss/mail/Default]
[0m[0m03:23:22,072 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
[0m[0m03:23:22,126 INFO [org.jboss.remoting] (MSC service thread 1-1) JBoss Remoting version 4.0.6.Final
[0m[0m03:23:22,394 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017527: Creating file handler for path /home/user/software/wildfly-8.2.0.Final/welcome-content
[0m[0m03:23:22,472 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017525: Started server default-server.
[0m[0m03:23:22,489 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017531: Host default-host starting
[0m[0m03:23:22,645 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017519: Undertow HTTP listener default listening on /127.0.0.1:8080
[0m[0m03:23:23,195 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-6) JBAS015012: Started FileSystemDeploymentService for directory /home/user/software/wildfly-8.2.0.Final/standalone/deployments
[0m[0m03:23:23,205 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
[0m[0m03:23:23,562 INFO [org.jboss.ws.common.management] (MSC service thread 1-4) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.3.2.Final
[0m[0m03:23:23,777 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
[0m[0m03:23:23,778 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
[0m[0m03:23:23,779 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.0.Final "Tweek" started in 5650ms - Started 184 of 234 services (82 services are lazy, passive or on-demand)
[0mConnected to server
[2015-02-06 03:23:23,964] Artifact admin:war: Artifact is being deployed, please wait...
[2015-02-06 03:23:23,965] Artifact web:war: Artifact is being deployed, please wait...
[0m03:23:24,384 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "admin.war" (runtime-name: "admin.war")
[0m[0m03:23:24,849 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017534: Registered web context: /admin
[0m[0m03:23:25,335 INFO [org.jboss.as.server] (management-handler-thread - 3) JBAS018559: Deployed "admin.war" (runtime-name : "admin.war")
[0m[2015-02-06 03:23:25,366] Artifact admin:war: Artifact is deployed successfully
[2015-02-06 03:23:25,366] Artifact admin:war: Deploy took 1,402 milliseconds
[0m03:23:25,632 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "web.war" (runtime-name: "web.war")
[0m[33m03:23:26,995 WARN [org.jboss.as.ee] (MSC service thread 1-2) JBAS011006: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
[0m[33m03:23:27,005 WARN [org.jboss.as.ee] (MSC service thread 1-2) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
[0m[0m03:23:27,084 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.3)
[0m[0m03:23:27,102 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) JBAS010417: Started Driver service with driver-name = web.war_org.postgresql.Driver_9_3
[0m[0m03:23:27,140 INFO [io.undertow.servlet] (MSC service thread 1-4) Spring WebApplicationInitializers detected on classpath: [somem.web.configuration.WebAppInitializer#4aedfc7b]
[0m[0m03:23:27,193 INFO [stdout] (MSC service thread 1-4) test222
[0m[0m03:23:27,205 INFO [io.undertow.servlet] (MSC service thread 1-4) Initializing Spring root WebApplicationContext
[0m[0m03:23:27,208 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Root WebApplicationContext: initialization started
[0m[0m03:23:27,279 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Refreshing Root WebApplicationContext: startup date [Fri Feb 06 03:23:27 ICT 2015]; root of context hierarchy
[0m[0m03:23:27,352 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Registering annotated classes: [class somem.persistence.config.JDOConfiguration]
[0m[0m03:23:27,523 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-4) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[0m[0m03:23:28,409 INFO [stdout] (MSC service thread 1-4) test system
[0m[0m03:23:28,451 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Root WebApplicationContext: initialization completed in 1243 ms
[0m[0m03:23:28,454 INFO [io.undertow.servlet] (MSC service thread 1-4) Initializing Spring FrameworkServlet 'dispatcher'
[0m[0m03:23:28,454 INFO [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-4) FrameworkServlet 'dispatcher': initialization started
[0m[0m03:23:28,458 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Feb 06 03:23:28 ICT 2015]; parent: Root WebApplicationContext
[0m[0m03:23:28,460 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-4) Registering annotated classes: [class somem.web.configuration.WebConfiguration]
[0m[0m03:23:28,600 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-4) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[0m[0m03:23:28,844 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-4) Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String somem.web.controller.MainController.test(javax.servlet.http.HttpServletResponse)
[0m[0m03:23:28,890 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (MSC service thread 1-4) Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[0m[0m03:23:28,902 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (MSC service thread 1-4) Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]
[0m[0m03:23:29,235 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-4) HV000001: Hibernate Validator 5.1.3.Final
[0m[0m03:23:29,328 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (MSC service thread 1-4) Looking for #ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Feb 06 03:23:28 ICT 2015]; parent: Root WebApplicationContext
[0m[0m03:23:29,414 INFO [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-4) FrameworkServlet 'dispatcher': initialization completed in 960 ms
[0m[0m03:23:29,414 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017534: Registered web context: /web
[0m[0m03:23:29,672 INFO [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "web.war" (runtime-name : "web.war")
[0m[2015-02-06 03:23:29,708] Artifact web:war: Artifact is deployed successfully
[2015-02-06 03:23:29,708] Artifact web:war: Deploy took 5,743 milliseconds
datanucleus.autoCreateSchema is not a valid property in DataNucleus 4.0 (see the properties doc), as defined by the migration guide from v3.x. Using datanucleus.schema.autoCreateAll would make more sense.

Resources