This commit is contained in:
2026-05-21 23:48:44 +02:00
parent 1f51386b57
commit 7859b5c801
8 changed files with 254 additions and 11 deletions
+7
View File
@@ -43,6 +43,13 @@
<artifactId>lombok</artifactId>
<version>1.18.46</version>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
@@ -0,0 +1,18 @@
package org.example.demo.uebung5.aufgabe21;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.inject.Singleton;
import org.jboss.logging.Logger;
@ApplicationScoped
public class LoggerProducer {
@Produces
public Logger produceLogger(InjectionPoint ip) {
// Ermittelt die Klasse, in die der Logger injiziert wird
Class<?> targetClass = ip.getMember().getDeclaringClass();
return Logger.getLogger(targetClass);
}
}
@@ -0,0 +1,17 @@
package org.example.demo.uebung5.aufgabe21;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.Stateless;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
@Stateless
public class TestLoggerService {
@Inject
private Logger logger;
public void logBeispiel() {
logger.info("CDI-Logger funktioniert! Diese Nachricht kommt vom injizierten Logger.");
}
}
+3 -4
View File
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_1.xsd">
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_1.xsd" bean-discovery-mode="annotated">
</beans>
</beans>
+1 -4
View File
@@ -1,6 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
version="4.0" bean-discovery-mode="annotated">
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd" version="4.0" bean-discovery-mode="annotated">
</beans>