Migration Deep Dive für 25 · JNDI und Service-Auflösung öffnen →
⌂ ÜbersichtAlle Vergleiche
Modul 25 · 100 % Codeabdeckung

JNDI und Service-Auflösung

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.

8Legacy-Dateien
5Modern-Dateien
141 → 82Codezeilen
14/14vollständig erfasst

Fachliche Einordnung

Legacy

JNDI Service Locator

Der Use Case kennt einen String-Namen und löst den Service zur Laufzeit über Context.lookup auf.

Modern

Constructor Injection über einen Port

Der Use Case erhält GreetingPort direkt über den Konstruktor.

Vergleichsfokus: Alle Dateien werden nach technischer Rolle und fachlicher Verantwortung gruppiert.
Wichtige Abgrenzung: One-to-many-Änderungen werden als Gruppe dargestellt; eine künstliche 1:1-Zuordnung wird vermieden.

Vollständige Abdeckungsmatrix

Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.

VergleichsgruppeLegacy-DateienModern-DateienLegacy-ZeilenModern-ZeilenÄhnlichkeit
Build-Konfiguration11343940%
Fachlicher Port, Service, Use-Case und Test44424331%
JNDI-Infrastruktur und Test306500%

Gemeinsame Modulstruktur

Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.

Gemeinsam · 19 Zeilenpom.xml
<?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>java-modernization-deep-dive</artifactId>
        <version>1.0.0</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>25jndiserviceresolution-pair</artifactId>
    <packaging>pom</packaging>
    <name>JNDI und Service-Auflösung: Legacy und Modern</name>
    <modules>
        <module>legacy</module>
        <module>modern</module>
    </modules>
</project>

Alle semantischen Codevergleiche

01Build-KonfigurationDirektvergleich · Legacy 34 / Modern 39 Zeilen · Ähnlichkeit 40%

JNDI- und moderne DI-Konfiguration wird verglichen.

Legacy-DateienModern-DateienEinordnung
pom.xmlpom.xmlDirektvergleich
Semantische Ähnlichkeit: 40%

Legacy

Legacy · 34 Zeilenlegacy/pom.xml
<?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>25jndiserviceresolution-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>jndi-legacy</artifactId>
            <packaging>jar</packaging>
            <name>JNDI Legacy</name>

            <dependencies>

<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>

Modern

Modern · 39 Zeilenmodern/pom.xml
<?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>25jndiserviceresolution-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>service-resolution-modern</artifactId>
            <packaging>jar</packaging>
            <name>Service Resolution Modern</name>

            <dependencies>
                <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</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>
02Fachlicher Port, Service, Use-Case und TestDirektvergleich · Legacy 42 / Modern 43 Zeilen · Ähnlichkeit 31%

Fachliche Rollen bleiben erhalten, die Auflösung wird vereinfacht.

Legacy-DateienModern-DateienEinordnung
GreetingPort.java
GreetingService.java
LegacyGreetingUseCase.java
LegacyGreetingUseCaseTest.java
GreetingPort.java
GreetingService.java
GreetingUseCase.java
GreetingUseCaseTest.java
Direktvergleich
Semantische Ähnlichkeit: 31%

Legacy

package at.aydin.lab.jndi.legacy;

// Design Pattern: Service Locator
// Zweck: Zeigt die versteckte Laufzeitabhängigkeit auf JNDI-Name und Naming-Infrastruktur.
public final class LegacyGreetingUseCase {
    private final JndiServiceLocator locator;
    public LegacyGreetingUseCase(JndiServiceLocator locator) {
        this.locator = locator;
    }

    public String execute(String name) {
        GreetingPort port = locator.resolve("service/greeting", GreetingPort.class);
        return port.greet(name);
    }
}
package at.aydin.lab.jndi.legacy;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class LegacyGreetingUseCaseTest {
    @Test
    void resolvesTheDependencyByJndiName() throws Exception {
        MemoryContext context = new MemoryContext();
        context.rebind("service/greeting", new GreetingService());
        LegacyGreetingUseCase useCase = new LegacyGreetingUseCase(new JndiServiceLocator(context));
        assertEquals("Hallo Test", useCase.execute("Test"));
    }
}

Modern

package at.aydin.lab.jndi.modern;

import org.springframework.stereotype.Component;

@Component
public class GreetingUseCase {
    private final GreetingPort port;
    public GreetingUseCase(GreetingPort port) {
        this.port = port;
    }

    public String execute(String name) {
        return port.greet(name);
    }
}
package at.aydin.lab.jndi.modern;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class GreetingUseCaseTest {
    @Test
    void injectsExplicitPort() {
        assertEquals("Hallo Test", new GreetingUseCase(new GreetingService()).execute("Test"));
    }
}
03JNDI-Infrastruktur und TestEntfällt in Modern · Legacy 65 / Modern 0 Zeilen · Ähnlichkeit 0%

Service Locator und MemoryContext entfallen vollständig zugunsten direkter Injection.

Legacy-DateienModern-DateienEinordnung
JndiServiceLocator.java
MemoryContext.java
JndiServiceLocatorTest.java
Entfällt in Modern
Semantische Ähnlichkeit: 0%

Legacy

package at.aydin.lab.jndi.legacy;

import javax.naming.*;

// Design Pattern: Service Locator
// Zweck: Versteckt JNDI-Lookups, behält aber die Laufzeitabhängigkeit von String-Namen.
public final class JndiServiceLocator {
    private final Context context;
    public JndiServiceLocator(Context context) {
        this.context = context;
    }

    public <T> T resolve(String name, Class<T> type) {
        try {
            return type.cast(context.lookup(name));
        } catch (NamingException ex) {
            throw new IllegalStateException(ex);
        }
    }
}
package at.aydin.lab.jndi.legacy;

import javax.naming.*;
import java.util.*;

public final class MemoryContext extends InitialContext {
    private static final Map<String, Object> VALUES = new HashMap<>();
    public MemoryContext() throws NamingException {
        super(true);
    }

    @Override
    public Object lookup(String name) throws NamingException {
        Object value = VALUES.get(name);
        if (value == null) throw new NameNotFoundException(name);
        return value;
    }

    @Override
    public void bind(String name, Object obj) throws NamingException {
        if (VALUES.putIfAbsent(name, obj) != null) throw new NameAlreadyBoundException(name);
    }

    @Override
    public void rebind(String name, Object obj) {
        VALUES.put(name, obj);
    }

    @Override
    public void close() {
    }
}
package at.aydin.lab.jndi.legacy;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class JndiServiceLocatorTest {
    @Test
    void resolvesStringName() throws Exception {
        var c = new MemoryContext();
        c.rebind("service/greeting", "Hallo");
        assertEquals("Hallo", new JndiServiceLocator(c).resolve("service/greeting", String.class));
    }
}

Modern

Kein Modern-Gegenstück. Diese Verantwortung entfällt.
⌂ Cockpit