WildFly | JBoss Application Server | Openshift tutorials

Tutorials for WildFly Application Server, Openshift, JBoss Projects and Enterprise Applications

  • Home
  • GET ME STARTED!GET ME STARTED!
  • WildFly
    • Configuration
    • Monitoring
    • JBoss AS 7 tutorials
    • Logging
    • Command Line
    • Performance
    • AS Security
    • JMS
    • Datasource
    • Clustering
    • Deployment
    • WildFly tutorials
    • JBoss eap
    • WildFly Swarm
  • BPM
    • JBPM 3-4
    • Activiti
    • BPMN 2.0
    • Drools
    • jBPM 5
    • jBPM 6
  • Projects
    • Arquillian
    • Netty
    • ModeShape
    • IronJacamar (JCA)
    • Byteman
    • Hibernate
    • JBoss Forge
    • Maven tutorials
      • Maven and Hibernate
      • Maven and JBoss/WildFly
    • Quartz & TimeMachine
    • RESTEasy
    • CDI using Weld
    • Remoting
    • Infinispan
    • Spring
    • Teiid
    • Keycloak
    • Windup
    • JBoss Fuse
  • Java EE
    • JSF
    • Java EE Batch API
    • WebSockets
    • CDI
    • Facelets
    • JPA
    • EJB
    • SOAP Web services
    • Servlets
    • Json
    • MongoDB
    • Jenkins
    • JAX-RS
    • Transactions
  • IDE
    • Eclipse tips
    • JBoss Tools for Eclipse
    • Netbeans
    • Eclipse microservices
  • SOA-Cloud
    • JBoss SOA
    • Cloud
    • Docker
    • DevOps
    • Openshift
  • Web
    • RichFaces
    • Primefaces
    • Icefaces
    • Web server
    • Vaadin
    • Struts and Tiles
  • Misc
    • Faqs
    • Vert-x
    • Zookeeper
    • Ansible
    • Java Stuff
    • Spring Boot tutorials
    • Camel
    • JRebel
    • Various tutorials
    • GraalVM
  • Old Stuff
    • JBoss Seam
    • GateIn Portal
    • Torquebox
    • Errai
    • Apiman
    • Apache ActiveMQ
  • Follow via Facebook
  • Follow via Twitter
  • Follow via Github
  • Follow RSS Feed

Search Mastertheboss

Our eBooks

Hibernate fetching performance tuning

Joining tables in SQL is the foundation of a relational database, as joins allow you to actually model relationships between tables. In plain JDBC, joins between tables are composed using native SQL statements. On the other hand, when using Hibernate/JPA this is greatly simplified as you will specify the relation between tables in terms of Objects. A key aspect of it is that, when you define a relationship in an ORM tool like Hibernate or JPA, you’ll also need to define the fetch type.

Written by Super User
Created: 02 January 2019
Last Updated: 02 January 2019
Hits: 761

Read more: Hibernate fetching performance tuning

0
0
0
s2smodern

How to manage WildFly metrics

Wildfly 15 has been released. One of the enhancements contained in it is the enhanced set of metrics that are exposed by the application server so that they can be consumed by the Openshift Console

Written by Super User
Created: 27 December 2018
Last Updated: 08 February 2019
Hits: 856

Read more: How to manage WildFly metrics

0
0
0
s2smodern

Getting Started with Infinispan - Part 1

This tutorial has been updated to work with the lastes Infinispan 9 release.

Infinispan is a distributed in-memory key/value data grid. An in-memory data grid is a form of middleware that stores sets of data for use in one or more applications, primarily in memory. The data is typically distributed across grid nodes in a network. The data stored in the grid can be unstructured.

Created: 21 December 2018
Last Updated: 23 December 2018
Hits: 31208

Read more: Getting Started with Infinispan - Part 1

0
0
0
s2smodern

Getting started with GraalVM

GraalVM is an extension of the Java Virtual Machine that is able to support several languages and execution modes. The Graal project includes a new high performance Java compiler, called Graal, which can be used in a just-in-time configuration on the HotSpot VM, or in an ahead-of-time configuration on the SubstrateVM.

Written by Super User
Created: 20 December 2018
Last Updated: 20 December 2018
Hits: 576

Read more: Getting started with GraalVM

0
0
0
s2smodern

How to capture WildFly lifecycle notifications

This tutorial describes how to capture lifecycle events notifications in WildFly 11 and above.

Written by Super User
Created: 19 December 2018
Last Updated: 19 December 2018
Hits: 709

Read more: How to capture WildFly lifecycle notifications

0
0
0
s2smodern

Top 5 solutions for Java Http Clients

In this tutorial we will check some of the best solutions if you want to implement an Http Client. You can run the Http Client on the top of WildFly application server or as part of any Java process.

Written by Super User
Created: 10 December 2018
Last Updated: 11 December 2018
Hits: 934

Read more: Top 5 solutions for Java Http Clients

0
0
0
s2smodern

Spring Boot Hello World on WildFly

This article has been updated and tested with WildFly 14 and Spring Boot 2.2.0 release.

Spring Boot offers a new paradigm for developing Spring applications with more agility while focusing on your business methods rather than the thought of configuring Spring itself. Spring Boot does not require complex configuration files as it is able to discover classes by looking in the classpath of your applications and building a single runnable JAR of it, which makes it convenient to make your service portable too.

Creating a Spring Boot project

The simplest way to get started with Spring Boot is via the Spring Boot inizializer that is available on http://start.spring.io/

From there, choose the Spring Boot starters that you want to be included and artifactId and groupId. Also you can opt for a Maven project or a Gradle project.

Spring boot to wildfly tutorial

As you can see, we have added only the "web" dependencies that will enable us to create a simple Web application with a REST endpoint.

Your first application

The Spring Boot Initilizer has created for us a sample application named SpringbootwildflyApplication. We will add some simple logic in it to map a GET request with a REST text resource. Copy in it the following text:

package com.mastertheboss.springboot.springbootwildfly;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@SpringBootApplication
public class SpringbootwildflyApplication   {
 
    public static void main(String[] args) {
        SpringApplication.run(SpringbootwildflyApplication.class, args);
    }
}
 
 
@RestController
class HelloController {
 
    @RequestMapping("/hello/{name}")
    String hello(@PathVariable String name) {
         
             return "Hi "+name+" !";
              
    }
}

Let's see more in detail. The class is annotated with a @SpringBootAnnotation annotation. This is equivalent to applying the following Spring annotations:

  • @Configuration which identifies the class as a source of bean definitions for the application context.
  • @EnableAutoConfiguration which enables Spring Boot to add beans based on the application's classpath, and various property settings.
  • @ComponentScan which tells Spring to look for other beans,configurations, and services in the same package as your application class so that you will be able to find the SimpleBean class.

Next, we have used the @RestController annotation to annotate a class that will encompass all of our REST APIs.  We will also use the @RequestMapping annotation to define the URL path to our API as well as HTTP method and path parameters for our APIs.

The is the pom.xml file used to build and package our first Project:

<?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">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.0.BUILD-SNAPSHOT</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.mastertheboss.springboot</groupId>
	<artifactId>springbootwildfly</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>
	<name>springbootwildfly</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

	<repositories>
		<repository>
			<id>spring-snapshots</id>
			<name>Spring Snapshots</name>
			<url>https://repo.spring.io/snapshot</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

	<pluginRepositories>
		<pluginRepository>
			<id>spring-snapshots</id>
			<name>Spring Snapshots</name>
			<url>https://repo.spring.io/snapshot</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</pluginRepository>
		<pluginRepository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>


</project>

As you can see, the list of dependencies is really minimal. You will find some extra repository configuration if you are using a snapshot version (as in this case) of Spring Boot. All you have to do, in order to create the runnable JAR file is:

$ mvn clean package

You will generate a simple SpringBootBasic.jar file which can be run with:

$ java -jar target/springbootwildfly-0.0.1-SNAPSHOT.jar

The embedded Tomcat Web server will start, we can test that our application is working as follows:

Spring Boot Hello World JBoss

Porting SpringBoot on a Java EE Container

Porting the Hello World application on a Java EE Container such as WildFly requires a few tweaks, mostly due to the fact that the application must be initialized and run by a Servlet container which is embedded into the application server. The first change will be extending the org.springframework.boot.web.servlet.support.SpringBootServletInitializer which is a WebApplicationInitializer to run a SpringApplication from a traditional WAR deployment:

package com.mastertheboss.springboot.springbootwildfly;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// Spring Boot 2.x
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

// Spring Boot 1.x
//import org.springframework.boot.web.support.SpringBootServletInitializer;
 
@SpringBootApplication
public class SpringbootwildflyApplication extends SpringBootServletInitializer {
 
    public static void main(String[] args) {
        SpringApplication.run(applicationClass, args);
    }
 
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }
 
    private static Class<SpringbootwildflyApplication> applicationClass = SpringbootwildflyApplication.class;
}
 
@RestController
class HelloController {
 
    @RequestMapping("/hello/{name}")
    String hello(@PathVariable String name) {
 
        return "Hi " + name + " !";
 
    }
}

Please note that we are using the org.springframework.boot.web.servlet.support.SpringBootServletInitializer and not the org.springframework.boot.web.support.SpringBootServletInitializer that has been deprecated in Spring Boot 2!

Next, some changes are also required in the pom.xml, in order to exclude the default Tomcat embedded Web server initializer and include the Servlet dependency in order to be able to compile the project:

<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>
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.2.0.BUILD-SNAPSHOT</version>
      <relativePath />
      <!-- lookup parent from repository -->
   </parent>
   <groupId>com.mastertheboss.springboot</groupId>
   <artifactId>springbootwildfly</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>war</packaging>
   <name>springbootwildfly</name>
   <description>Demo project for Spring Boot</description>
   <properties>
      <java.version>1.8</java.version>
   </properties>
   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
         <exclusions>
            <exclusion>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
         </exclusions>
      </dependency>
      <dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>javax.servlet-api</artifactId>
         <version>3.1.0</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
      </dependency>
   </dependencies>
   <build>
      <finalName>springbootwildfly</finalName>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>
   <repositories>
      <repository>
         <id>spring-snapshots</id>
         <name>Spring Snapshots</name>
         <url>https://repo.spring.io/snapshot</url>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </repository>
      <repository>
         <id>spring-milestones</id>
         <name>Spring Milestones</name>
         <url>https://repo.spring.io/milestone</url>
         <snapshots>
            <enabled>false</enabled>
         </snapshots>
      </repository>
   </repositories>
   <pluginRepositories>
      <pluginRepository>
         <id>spring-snapshots</id>
         <name>Spring Snapshots</name>
         <url>https://repo.spring.io/snapshot</url>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </pluginRepository>
      <pluginRepository>
         <id>spring-milestones</id>
         <name>Spring Milestones</name>
         <url>https://repo.spring.io/milestone</url>
         <snapshots>
            <enabled>false</enabled>
         </snapshots>
      </pluginRepository>
   </pluginRepositories>
</project>

Now compile as usual the project with:

$ mvn clean package

You will generate a SpringBootBasic.war file which can be deployed with:

$ cp target/springbootwildfly.war %JBOSS_HOME/standalone/deployments

You will notice from the application server logs that Spring Boot has been started:

11:28:34,664 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 83) 2 Spring WebApplicationInitializers detected on classpath
11:28:35,197 INFO  [stdout] (ServerService Thread Pool -- 83) 
11:28:35,211 INFO  [stdout] (ServerService Thread Pool -- 83)   .   ____          _            __ _ _
11:28:35,212 INFO  [stdout] (ServerService Thread Pool -- 83)  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
11:28:35,212 INFO  [stdout] (ServerService Thread Pool -- 83) ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
11:28:35,212 INFO  [stdout] (ServerService Thread Pool -- 83)  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
11:28:35,212 INFO  [stdout] (ServerService Thread Pool -- 83)   '  |____| .__|_| |_|_| |_\__, | / / / /
11:28:35,212 INFO  [stdout] (ServerService Thread Pool -- 83)  =========|_|==============|___/=/_/_/_/
11:28:35,213 INFO  [stdout] (ServerService Thread Pool -- 83)  :: Spring Boot ::  (v2.2.0.BUILD-SNAPSHOT)
11:28:35,213 INFO  [stdout] (ServerService Thread Pool -- 83) 

We can test that our application is working as follows:

Spring Boot Hello World JBoss

Troubleshooting

A frequent issue when building your Spring Boot to WildFly project is the following error:

java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig

 This can happen if you are using a Servlet API dependencies pre 3.x. Update your pom.xml with the 3.1.0 (or newer) javax.servlet-api !

Source code

You can check the source code for this article at: https://github.com/fmarchioni/mastertheboss/tree/master/spring/springbootwildfly

That's all! In the next tutorial SpringBoot with JPA on WildFly we will learn how to use JPA with a Spring Boot application.

Do you want some more Spring stuff ? check Spring Boot Tutorials !

Written by Super User
Created: 09 December 2018
Last Updated: 05 February 2019
Hits: 49294
0
0
0
s2smodern

Configuring Persistent Storage on Openshift

This tutorial will introduce you to configuring Storage on Openshift and use it for building stateful applications

Written by wildfly guru
Created: 30 November 2018
Last Updated: 03 December 2018
Hits: 781

Read more: Configuring Persistent Storage on Openshift

0
0
0
s2smodern

Getting started with Openshift using OKD

OKD is a distribution of Kubernetes optimized for continuous application development and multi-tenant deployment. OKD is the upstream Kubernetes distribution embedded in Red Hat OpenShift and can be used to add developer and operations-centric tools on top of Kubernetes to enable rapid application development, easy deployment and scaling, and long-term lifecycle maintenance for small and large teams.

Written by Super User
Created: 26 November 2018
Last Updated: 27 November 2018
Hits: 789

Read more: Getting started with Openshift using OKD

0
0
0
s2smodern

Introduction to Thorntail

Thorntail is the new name for WildFly Swarm, which can be used to create micro-services-like Java Enterprise Applications. In this tutorial we will learn how to create a simple MicroService application using Thorntail and how to migrate from WildFly Swarm.

Written by Super User
Created: 19 November 2018
Last Updated: 19 November 2018
Hits: 1369

Read more: Introduction to Thorntail

0
0
0
s2smodern

Getting started with Podman

Podman is a container runtime which provides the same features of Docker. The main difference is that it doesn’t require any running daemon (like dockerd) to run on your system. Pods and containers processes are created as children of the Podman tool. Besides it, it can also run without root privileges. So let’s see how we can use it to run some simple Linux containers and WildFly application server.

Written by Super User
Created: 12 November 2018
Last Updated: 12 November 2018
Hits: 1325

Read more: Getting started with Podman

0
0
0
s2smodern
  1. Introduction to Continuous Integration and Delivery
  2. How to populate a dataTable from a JSON file
  3. Export your dataTable to Excel and PDF using Primefaces
  4. Using OpenTracing API with WildFly application server
  5. Configuring Applications with Eclipse MicroProfile Config
  6. Configuring Agroal Datasource on WildFly
  7. Using Templates in Jenkins Job Builder
  8. Jenkins Job Builder quickstart
  9. Develop your Enterprise applications on the Cloud with Eclipse Che
  10. Manage Server Resources with Arquillian
  11. Creating your first Jenkins Pipeline
  12. Using ELK stack to collect WildFly / JBoss EAP metrics
  13. Monitoring WildFly Container image - Part 2: JVisualVM
  14. Monitoring WildFly Container image - Part 1: JConsole
  15. How to deploy applications to WildFly using Cargo

Page 1 of 21

  • 1
  • 2
  • 3
  • 4
  • ...
  • 6
  • 7
  • 8
  • 9
  • 10

Back to Top

© 2019 WildFly | JBoss Application Server | Openshift tutorials