BAEL-624 How to setup WildFly (#2667)
* bean dependency injection types tutorial * Edited and added the JUnit tests. * Edited the bean.xml files for new class names. * Deleted evaluation article. * first phase - TODO: JPA * Project for How to setup Wildfly * Deleted old project * Delted tests in EJB - test Servlet * LAST commit * Restored deleted files - accident * dependency corrections * reapply changes * eclipse Baeldung formatter file - format code * removed metadata
This commit is contained in:
committed by
adamd1985
parent
8cf77804c6
commit
390f56616f
@@ -0,0 +1,81 @@
|
||||
<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.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<modules>
|
||||
<module>widlfly-web</module>
|
||||
<module>wildfly-ear</module>
|
||||
<module>wildfly-jpa</module>
|
||||
<module>wildfly-ejb-interfaces</module>
|
||||
<module>wildfly-ejb</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- Dependencies for other libraries -->
|
||||
<!-- Dependency for java ee -->
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>7.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Dependency for wildfly -->
|
||||
<dependency>
|
||||
<groupId>org.wildfly.bom</groupId>
|
||||
<artifactId>wildfly-javaee7</artifactId>
|
||||
<version>10.1.0.Final</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<!-- Dependency on Hibernate -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.2.3.Final</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Dependency for ear module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildlfy-ear</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<type>ear</type>
|
||||
</dependency>
|
||||
<!-- Dependency for web module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildlfy-web</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<type>war</type>
|
||||
</dependency>
|
||||
<!-- Dependency for jpa module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildlfy-jpa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Dependency for EJB -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Dependency for EJB interfaces -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb-interfaces</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
<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>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>widlfly-web</artifactId>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- Dependency for java ee -->
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>7.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Dependency for JPA module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-jpa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Dependency for EJB interface module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb-interfaces</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Dependency for EJB interface module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import model.User;
|
||||
import wildfly.beans.UserBeanLocal;
|
||||
|
||||
/**
|
||||
* Servlet implementation class TestEJBServlet
|
||||
*/
|
||||
public class TestEJBServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@EJB
|
||||
private UserBeanLocal userBean;
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
List<User> users = userBean.getUsers();
|
||||
|
||||
response.getWriter()
|
||||
.append("The number of users is: " + users.size());
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import model.User;
|
||||
|
||||
/**
|
||||
* Servlet implementation class TestJPAServlet
|
||||
*/
|
||||
public class TestJPAServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@PersistenceContext(unitName = "wildfly-jpa")
|
||||
EntityManager em;
|
||||
|
||||
@Resource
|
||||
UserTransaction tx;
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public TestJPAServlet() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
Query q = em.createNamedQuery("User.findAll");
|
||||
List<User> users = q.getResultList();
|
||||
response.getWriter()
|
||||
.append("JPA users returned: " + users.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
*/
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<display-name>widlfly-web</display-name>
|
||||
<welcome-file-list>
|
||||
<welcome-file>index.html</welcome-file>
|
||||
<welcome-file>index.htm</welcome-file>
|
||||
<welcome-file>index.jsp</welcome-file>
|
||||
<welcome-file>default.html</welcome-file>
|
||||
<welcome-file>default.htm</welcome-file>
|
||||
<welcome-file>default.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
<servlet>
|
||||
<description></description>
|
||||
<display-name>TestJPAServlet</display-name>
|
||||
<servlet-name>TestJPAServlet</servlet-name>
|
||||
<servlet-class>TestJPAServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>TestJPAServlet</servlet-name>
|
||||
<url-pattern>/TestJPAServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet>
|
||||
<description></description>
|
||||
<display-name>TestEJBServlet</display-name>
|
||||
<servlet-name>TestEJBServlet</servlet-name>
|
||||
<servlet-class>TestEJBServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>TestEJBServlet</servlet-name>
|
||||
<url-pattern>/TestEJBServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
@@ -0,0 +1,62 @@
|
||||
<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>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>wildfly-ear</artifactId>
|
||||
<packaging>ear</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- Dependency for web module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>widlfly-web</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<type>war</type>
|
||||
</dependency>
|
||||
<!-- Dependency for web module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-jpa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Dependency for EJB -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb</artifactId>
|
||||
</dependency>
|
||||
<!-- Dependency for EJB -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb-interfaces</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-ear-plugin</artifactId>
|
||||
<version>2.10.1</version>
|
||||
<configuration>
|
||||
<defaultLibBundleDir>lib/</defaultLibBundleDir>
|
||||
<version>7</version>
|
||||
<modules>
|
||||
<webModule>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>widlfly-web</artifactId>
|
||||
<contextRoot>/wildfly</contextRoot>
|
||||
</webModule>
|
||||
</modules>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.wildfly.plugins</groupId>
|
||||
<artifactId>wildfly-maven-plugin</artifactId>
|
||||
<version>1.2.0.Final</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
<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>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>wildfly-ejb-interfaces</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Dependency for EJB javax -->
|
||||
<dependency>
|
||||
<groupId>javax.ejb</groupId>
|
||||
<artifactId>javax.ejb-api</artifactId>
|
||||
<version>3.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Dependency for JPA module -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-jpa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package wildfly.beans;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import model.User;
|
||||
|
||||
@Local
|
||||
public interface UserBeanLocal {
|
||||
|
||||
List<User> getUsers();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package wildfly.beans;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Remote;
|
||||
|
||||
import model.User;
|
||||
|
||||
@Remote
|
||||
public interface UserBeanRemote {
|
||||
|
||||
List<User> getUsers();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<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>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>wildfly-ejb</artifactId>
|
||||
<packaging>ejb</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- Dependency for EJB javax -->
|
||||
<dependency>
|
||||
<groupId>javax.ejb</groupId>
|
||||
<artifactId>javax.ejb-api</artifactId>
|
||||
<version>3.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Dependency for java ee -->
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Dependency for JPA -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
</dependency>
|
||||
<!-- Dependency for EJB Local and Remote -->
|
||||
<dependency>
|
||||
<groupId>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb-interfaces</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-ejb-plugin</artifactId>
|
||||
<configuration>
|
||||
<ejbVersion>3.2</ejbVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,24 @@
|
||||
package wildfly.beans;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import model.User;
|
||||
|
||||
/**
|
||||
* Session Bean implementation class UserBean
|
||||
*/
|
||||
@Stateless
|
||||
public class UserBean implements UserBeanRemote, UserBeanLocal {
|
||||
@PersistenceContext(unitName = "wildfly-jpa")
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
public List<User> getUsers() {
|
||||
return em.createNamedQuery("User.findAll")
|
||||
.getResultList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<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>com.baeldung.wildfly</groupId>
|
||||
<artifactId>wildfly-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>wildfly-jpa</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Dependencies for other libraries -->
|
||||
<!-- Dependency for JPA -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,51 @@
|
||||
package model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* The persistent class for the users database table.
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")
|
||||
public class User implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private String username;
|
||||
|
||||
private String email;
|
||||
|
||||
@Column(name = "postal_number")
|
||||
private Integer postalNumber;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Integer getPostalNumber() {
|
||||
return this.postalNumber;
|
||||
}
|
||||
|
||||
public void setPostalNumber(Integer postalNumber) {
|
||||
this.postalNumber = postalNumber;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="wildfly-jpa" transaction-type="JTA">
|
||||
<jta-data-source>java:/PostgresDS</jta-data-source>
|
||||
<class>model.User</class>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
Reference in New Issue
Block a user