[BAEL-1218] Guide to Spring EJB Integration (#3266)

* Evaluation article about types of bean injection in spring

* BAEL-1319 Quick Guide on Data.sql and Schema.sql Files in Spring

* Revert "Evaluation article about types of bean injection in spring"

This reverts commit eb071171673e0b8fa2b7ecffdad86f596e5fb114.

* BAEL-1218: adding spring-ejb and configuring ejb start and deploy

* BAEL-1218: adding spring

* BAEL-1218: wrapping all together

* BAEL-1218: new spring-ejb module

* BAEL-1218: tests and improvements

* BAEL-1218: removing moved files from old article

* BAEL-1218: code review requested changes

* BAEL-1218: test methods nomenclature correction

* BAEL-1418: removing tabs

* BAEL-1218: removing tabs

* BAEL-1218: correcting boot parent module path
This commit is contained in:
Allan Vital
2018-01-07 21:59:53 -02:00
committed by KevinGilmore
parent 09cbc1c6ee
commit cf32e14a9b
15 changed files with 463 additions and 0 deletions
+100
View File
@@ -0,0 +1,100 @@
<?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>
<artifactId>spring-ejb-client</artifactId>
<packaging>jar</packaging>
<name>spring-ejb-client</name>
<description>Spring EJB Client</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-5</relativePath>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>10.1.0.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.baeldung.spring.ejb</groupId>
<artifactId>ejb-remote-for-spring</artifactId>
<version>1.0.1</version>
<type>ejb</type>
</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>
@@ -0,0 +1,50 @@
package com.baeldung.springejbclient;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import com.baeldung.ejb.tutorial.HelloStatefulWorld;
import com.baeldung.ejb.tutorial.HelloStatelessWorld;
@SpringBootApplication
public class SpringEjbClientApplication {
@Bean
public Context context() throws NamingException {
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put("jboss.naming.client.ejb.context", true);
jndiProps.put("java.naming.provider.url", "http-remoting://localhost:8080");
return new InitialContext(jndiProps);
}
@Bean
public HelloStatelessWorld helloStatelessWorld(Context context) throws NamingException {
return (HelloStatelessWorld) context.lookup(this.getFullName(HelloStatelessWorld.class));
}
@Bean
public HelloStatefulWorld helloStatefulWorld(Context context) throws NamingException {
return (HelloStatefulWorld) context.lookup(this.getFullName(HelloStatefulWorld.class));
}
@SuppressWarnings("rawtypes")
private String getFullName(Class classType) {
String moduleName = "ejb-remote-for-spring/";
String beanName = classType.getSimpleName();
String viewClassName = classType.getName();
return moduleName + beanName + "!" + viewClassName;
}
public static void main(String[] args) {
SpringApplication.run(SpringEjbClientApplication.class, args);
}
}
@@ -0,0 +1,30 @@
package com.baeldung.springejbclient.endpoint;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.ejb.tutorial.HelloStatefulWorld;
import com.baeldung.ejb.tutorial.HelloStatelessWorld;
@RestController
public class HomeEndpoint {
private HelloStatelessWorld helloStatelessWorld;
private HelloStatefulWorld helloStatefulWorld;
public HomeEndpoint(HelloStatelessWorld helloStatelessWorld, HelloStatefulWorld helloStatefulWorld) {
this.helloStatelessWorld = helloStatelessWorld;
this.helloStatefulWorld = helloStatefulWorld;
}
@GetMapping("/stateless")
public String getStateless() {
return helloStatelessWorld.getHelloWorld();
}
@GetMapping("/stateful")
public String getStateful() {
return helloStatefulWorld.getHelloWorld() + " called " + helloStatefulWorld.howManyTimes() + " times";
}
}
@@ -0,0 +1,3 @@
server.port=8081
#logging.level.root=DEBUG
@@ -0,0 +1,11 @@
package com.baeldung.springejbclient;
import org.junit.Test;
public class SpringEjbClientApplicationIntegrationTest {
@Test
public void contextLoads() {
}
}