EJB 2 Session Bean mit Home/Remote Interfaces
Lifecycle, Remote-Vertrag und Lookup werden über EJB-2-Interfaces und Containerkonventionen modelliert.
Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.
Lifecycle, Remote-Vertrag und Lookup werden über EJB-2-Interfaces und Containerkonventionen modelliert.
Ein POJO-Service trägt die Fachlogik; ein separater Controller kann den Transport übernehmen.
Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.
| Vergleichsgruppe | Legacy-Dateien | Modern-Dateien | Legacy-Zeilen | Modern-Zeilen | Ähnlichkeit |
|---|---|---|---|---|---|
| Build-Konfiguration | 1 | 1 | 34 | 39 | 36% |
| Remote-/Home-Vertrag und HTTP-Anwendung | 2 | 2 | 18 | 28 | 8% |
| Service-Implementierung und Test | 2 | 2 | 37 | 24 | 30% |
Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.
EJB- und Spring-Web/Service-Abhängigkeiten werden verglichen.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| pom.xml | pom.xml | Direktvergleich Semantische Ähnlichkeit: 36% |
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>27ejbservices-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>ejb-legacy</artifactId>
<packaging>jar</packaging>
<name>EJB Legacy</name>
<dependencies>
<dependency><groupId>javax.ejb</groupId><artifactId>javax.ejb-api</artifactId><version>3.2.2</version></dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>27ejbservices-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>service-rest-modern</artifactId>
<packaging>jar</packaging>
<name>Service REST Modern</name>
<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.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>Container-spezifische Remote-Erzeugung wird durch HTTP-Adapter und Boot-Anwendung ersetzt.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| OrderRemote.java OrderHome.java | OrderController.java OrderApplication.java | Direktvergleich Semantische Ähnlichkeit: 8% |
package at.aydin.lab.ejb.legacy;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
// Design Pattern: Remote Facade
// Zweck: Grobgranulare Remote-Schnittstelle reduziert verteilte Einzelaufrufe.
public interface OrderRemote extends EJBObject {
String placeOrder(String sku, int quantity) throws RemoteException;
}package at.aydin.lab.ejb.legacy;
import javax.ejb.*;
import java.rmi.RemoteException;
public interface OrderHome extends EJBHome {
OrderRemote create() throws CreateException, RemoteException;
}package at.aydin.lab.ejb.modern;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/orders")
public class OrderController {
private final OrderService service;
public OrderController(OrderService service) {
this.service = service;
}
@PostMapping
public String order(@RequestParam String sku, @RequestParam int quantity) {
return service.placeOrder(sku, quantity);
}
}package at.aydin.lab.ejb.modern;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
}
}Session Bean wird einer POJO-Service-Komponente gegenübergestellt.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| OrderSessionBean.java OrderSessionBeanTest.java | OrderService.java OrderServiceTest.java | Direktvergleich Semantische Ähnlichkeit: 30% |
package at.aydin.lab.ejb.legacy;
import javax.ejb.*;
// Design Pattern: Session Facade
// Zweck: Bündelt fachlichen Bestellablauf in einer serverseitigen Session-Komponente.
public class OrderSessionBean implements SessionBean {
public String placeOrder(String sku, int quantity) {
return "ORDERED " + quantity + " x " + sku;
}
public void ejbCreate() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbRemove() {
}
public void setSessionContext(SessionContext context) {
}
}package at.aydin.lab.ejb.legacy;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class OrderSessionBeanTest {
@Test
void executesBusinessMethod() {
assertEquals("ORDERED 2 x A", new OrderSessionBean().placeOrder("A", 2));
}
}package at.aydin.lab.ejb.modern;
import org.springframework.stereotype.Service;
// Design Pattern: Service Layer
// Zweck: Fachlogik ist containerleicht, lokal testbar und nicht an RemoteObject gebunden.
@Service
public class OrderService {
public String placeOrder(String sku, int quantity) {
if (quantity <= 0) throw new IllegalArgumentException("quantity");
return "ORDERED " + quantity + " x " + sku;
}
}package at.aydin.lab.ejb.modern;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class OrderServiceTest {
@Test
void placesOrder() {
assertEquals("ORDERED 2 x A", new OrderService().placeOrder("A", 2));
}
}