간단한 콩을 @WebService
에 삽입 할 수 없습니다. FlatFileNoteDAO
다음과 같이 정의된다 :JAX-WS & JSR 330 (Spring) - 의존성을 주입 할 수 없습니다.
@Named
@WebService(name = "NoteStorage", serviceName = "NoteStorageWS")
public class NoteStorageWS implements NoteStore {
private static final Log l = LogFactory.getLog(NoteStorageWS.class);
@Named("NoteDAO")
@Inject
private NoteDAO noteDAO;
public NoteStorageWS() {
super();
}
@Override
@WebMethod
public StorageState takeNote(String note) {
try {
l.info(format("Service received message: '%s'", note));
Note n = new Note();
n.setContent(note);
noteDAO.store(n);
} catch (Exception e) {
l.error(e);
return StorageState.FAILURE;
}
return StorageState.SUCCESS;
}
@WebMethod(exclude = true)
public void setNoteDAO(NoteDAO noteDAO) {
this.noteDAO = noteDAO;
}
}
NoteDAO
단지 구현이 : 정의 된 클래스 경로 및 javax.inject
종속 봄으로, 나는 몇 가지 기본 인터페이스 기반의 DAO 등 간단한 JAX-WS의 웹 서비스를 만들어
@Named("NoteDAO")
public class FlatFileNoteDAO implements NoteDAO {
private static final Log l = LogFactory.getLog(FlatFileNoteDAO.class);
@Override
public void store(Note n) {
if (n == null) {
throw new IllegalArgumentException("Note was null");
}
try {
l.info(format("Storing note '%s'", n));
FileWriter fileWriter = new FileWriter(new File("Note"));
fileWriter.write(format("%s\n", n.getContent()));
fileWriter.close();
} catch (IOException e) {
throw new DataAccessException(e);
}
}
}
내 web.xml을 말한다 :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>
나는 그것을 가리켜 글래스 피시에 응용 프로그램을 배포 을 target/note-ws/디렉토리에 복사하고 ?Tester
페이지를 통해 간단한 takeNote
메소드를 실행하십시오.
테스터 양식을 제출하면 noteDAO.store(n);
에 NullPointerException
이 표시됩니다. 이는 아마도 noteDAO가 주입되지 않았기 때문일 것입니다.
나는 봄이 컨텍스트 초기화 (자바 EE 컨텍스트)에 글래스 피쉬의 로그에 의해 호출 된 것을 확인할 수 있습니다
내 콩이 정의라고[#|2011-12-04T16:57:24.970+0000|INFO|glassfish3.1.1|org.springframework.context.annotation.ClassPathBeanDefinitionScanner|_ThreadID=256;_ThreadName=Thread-2;|JSR-330 'javax.inject.Named' annotation found and supported for component scanning|#]
[#|2011-12-04T16:57:25.653+0000|INFO|glassfish3.1.1|org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor|_ThreadID=256;_ThreadName=Thread-2;|JSR-330 'javax.inject.Inject' annotation found and supported for autowiring|#]
[#|2011-12-04T16:57:25.757+0000|INFO|glassfish3.1.1|org.springframework.beans.factory.support.DefaultListableBeanFactory|_ThreadID=256;_ThreadName=Thread-2;|Pre-instantiating singletons in org.s[email protected]9e39146: defining beans [noteStorageWS,NoteDAO,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy|#]
: noteStorageWS
, NoteDAO
을 등 -에.
아이디어가 있으십니까?
수정하려면 을 수정하십시오. JSR 330 - 종속성 주입 기능을 제공하기 위해 Spring을 사용하고 있습니다.
- 당신은 내가이거나이 추가로 필요하다고한다 말? –
어떤 JSR-330 구현을 사용하고 있습니까? –
원래 게시물에 나온 것처럼 Spring : "클래스 패스의 봄" –