[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:
committed by
KevinGilmore
parent
09cbc1c6ee
commit
cf32e14a9b
+50
@@ -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);
|
||||
}
|
||||
}
|
||||
+30
@@ -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
|
||||
Reference in New Issue
Block a user