Java EE 6에는 @Inject Principal principal;
과 같은 주입에 사용할 수있는 내장 된 javax.security.Principal
bean 유형이 있습니다.기본 제공 기본 bean 재정의
이것은 기본적으로 생성자 방법을 대신 제공하여 변경하는 방법이 있는지 궁금합니다.
프로듀서 메소드를 작성하면 배포 예외가 발생합니다.
예 프로듀서 :
my.package;
import javax.security.Principal;
public class MyProducer {
...
@Produces
public Principal obtainPrincipal() {
return getMyPrincipal();
}
}
예외 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [Principal] with qualifiers [@Default] at injection point [[parameter 1] of [constructor] @Inject public my.package.MyType(Principal, SomeOtherType)]. Possible dependencies [[Producer Method [Principal] with qualifiers [@Any @Default] declared as [[method] @Produces @SessionScoped protected my.package.MyProducer.obtainPrincipal()], Built-in Bean [java.security.Principal] with qualifiers [@Default]]]
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:278)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
그래서 질문은 - CDI의 유형에 내장 된 기본을 대체 할 수있는 방법이있다?
내가 왜이 프로젝트가 필요한지 알려주기 위해 프로젝트가 JAAS에서 Apache Shiro로 전환 중입니다. 주입 된 주체를 기반으로 무언가를 수행하는 기존 코드가 적당합니다. 그러나 Shiro는 웹 환경에서 HttpServlet 요청/응답 만 래핑하고 적절한 보안 관련 메서드를 재정의합니다. 그러나 그 경우에는 익명의 주체를 항상 반환하는 CDI로 전파되지 않습니다. , 더 배포 오류가없는이 경우
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<alternatives>
<class>my.package.MyPrincipal</class>
</alternatives>
</beans>
하지만 주입 :
my.package;
import javax.security.Principal;
@Alternative
public class MyPrincipal implements Principal {
...
@Override
public String getName() {
return getMyPrincipalName();
}
}
그런 beans.xml 환경에서 대체 가능 :
는 업데이트 은 또한 다음과 같은 시도 교장은 여전히 내 기본 설정이 아니라 기본 설정입니다.