how use spring ioc for SFS2X?

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

chainren
Posts: 2
Joined: 30 Aug 2012, 03:11

how use spring ioc for SFS2X?

Postby chainren » 30 Aug 2012, 06:10

hello everyone,I have a question.I want use spring framework for our SFS2X project,I saw a solution in this BBS.And I learned to put follow code in the init() method of myExection:
Thread.currentThread().getContextClassLoader();
ClassLoader extensionLoader = getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(extensionLoader);
ApplicationContext context = new GenericXmlApplicationContext(new
ClassPathResource("applicationContext.xml", extensionLoader));
Thread.currentThread().setContextClassLoader(origLoader);
But we found a prolem that: the service beans were injiected when sfs server started, and when we used this service bean in business logic it was null,throw NullPointException.
public void handleClientRequest(User arg0, ISFSObject arg1) {
//...
System.out.println("userService----------" + this.userService);// here print null when this method was called.
//...
}
So we come up with a plan can solve this prolem.I defined the service beans as "static",like this
public class UserRegister extends BaseClientRequestHandler {
private static UserService userService;

public void setUserService(UserService userService) {
this.userService = userService;
}

@Override
public void handleClientRequest(User arg0, ISFSObject arg1) {

}
}
But we thought this was not a good solution.because it would be more and more static variables.finally Memory overflow.I want to ask for advice,how to use spring in the sfs project.Thanks!
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: how use spring ioc for SFS2X?

Postby Lapo » 30 Aug 2012, 17:39

You posted under the Android client section. Are you planning to use Spring on an Android client?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: how use spring ioc for SFS2X?

Postby Lapo » 30 Aug 2012, 17:55

I am sorry, I have no idea, we don't use Spring. If you search in this forum there other users that have successfully integrated the two.
Personally I find Spring too heavy and complex to use, especially in the context of a server side Extension. Of course it is just my opinion, in any case I'd be curious to learn why do you plane to use it and what problems do you think it could solve.

Typically I would use Spring for IoC in a large java application to solve dependencies etc... but for a server side extension, even a big and sophisticated one it seems a bit too much.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
chainren
Posts: 2
Joined: 30 Aug 2012, 03:11

Re: how use spring ioc for SFS2X?

Postby chainren » 31 Aug 2012, 02:08

I‘m fortunately for your reply.Thanks very much.
I throught SFS2X support is not good for spring by the current versions.And there was a little of case about how to use spring work for SFS2X on the web site.I search for this,and found someone use spring work for SFS2X and succeeded in this forum.So I hope someone can Announce a successful case for learning.I need steps or Details to config the spring,how to get ApplicationContext instance, how to get beans.etc.
We develop java server use SFS2X,and the client is AS3.We use spring because we want to use it inject our beans,manage the transaction.Now we although use spring work for SFS2X java server reluctantly, we throught it was not a good solution.So I need for your help to give a perfectly detail case.Thanks very much!

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 25 guests