Hey, I think that @Inject doesn't work because DWR creates its own instance of your class and doesn't use the CDI managed one. You have basically two options here.
Your first option is to tell DWR to use the CDI managed instance of you class instead of creating a new one. As I'm not familiar with DWR I cannot tell you how to do this. But there seems to be a Spring support module for DWR, so it should be possible to do something similar for CDI. Your second option is to use BeanProvider.injectFields(this) somewhere in your class. This way DeltaSpike will inject all dependencies into your object even if it has been created by DWR. I hope this helps Christian 2013/11/10 十三郎 <[email protected]> > hi,erveryone. > > in a DWR RemoteMethod,dwr cant get injected bean automatical. > like this: > -------------- > import javax.inject.Inject; > import javax.inject.Named; > import org.apache.deltaspike.core.api.provider.BeanProvider; > import org.directwebremoting.annotations.RemoteMethod; > import org.directwebremoting.annotations.RemoteProxy; > @Named("Test") > @RemoteProxy //for dwr > public class Test > { > @Inject private User user; > @RemoteMethod //for dwr > public String test(){ > //i find dwr cant get @Inject bean > System.out.println("user is null ? "+(user == null)); > > //fortunately , i can get it in a manual way. but i dont wanna > this way > user=BeanProvider.getContextualReference(User.class,false); > System.out.println("user name is: "+user.getUsername()); > return user.getUsername(); > } > } > > import java.io.Serializable; > import javax.enterprise.context.SessionScoped; > import javax.inject.Named; > @SessionScoped > @Named > public class User implements Serializable{ > private static final long serialVersionUID = -559381017984772756L; > private String username="wuhenge"; > public String getUsername(){ > return this.username; > } > public void setUsername(String s){ > this.username=s; > } > } > -------- > after run this demo,i find dwr can get inject bean in a manual way.but i > dont wanna this way > > i try to add deltaspike servlet module,but that didnt work. > > the edition of dwr is latest on > http://ci.directwebremoting.org/bamboo/browse/DWRTRUNK-ALL-521/artifact. > > thanks erveryone!!!! > > -- Christian Kaltepoth Blog: http://blog.kaltepoth.de/ Twitter: http://twitter.com/chkal GitHub: https://github.com/chkal
