GWT & Spring

201 views
Skip to first unread message

Akram Moncer

unread,
Mar 8, 2012, 10:33:13 AM3/8/12
to google-we...@googlegroups.com
hello everybody;

can some one help me and give me how can i create webapp with spring framwork on back-end and GWT on front-end ?

--
Akram MONCER
Personne

Xybrek

unread,
Mar 8, 2012, 10:33:19 PM3/8/12
to Google-We...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To post to this group, send email to
> google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.

In most cases, Spring code is in the GWT RPC (server-side code). Best
approach would be through maven, also you might want to use Spring STS
Plugin if you are using Eclipse.

If you are able to have your GWT project a "Spring nature" then on your
GWT RPC code, you can apply the standard Spring codes, i.e
in your ServiceImpl code you can override:

@Override
public void init() ...
{
super.init();
WebApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
// Beans
dao = (MyDao)ctx.getBean("myDao");
}

@Override
public void doSomething() {
String something = dao.getSomething(...);
}

From here, you can use the beans to do something your app need to
accomplish.

Of course you should fix your applicationContext.xml and web.xml which
you can easily search the web on how to do this.

This is just the basic way to integrate GWT and Spring, as the topic is
very broad, you can integrate other complex things like Spring
authentication etc.

Hope this helps.

Akram Moncer

unread,
Mar 9, 2012, 2:46:16 AM3/9/12
to google-we...@googlegroups.com
think you very much

Le 9 mars 2012 04:33, Xybrek <xyb...@gmail.com> a écrit :
On 3/8/2012 11:33 PM, Akram Moncer wrote:
hello everybody;

can some one help me and give me how can i create webapp with spring
framwork on back-end and GWT on front-end ?

--
Akram MONCER
Personne

--
You received this message because you are subscribed to the Google
Groups "Google Web Toolkit" group.
To post to this group, send email to

To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.

In most cases, Spring code is in the GWT RPC (server-side code). Best approach would be through maven, also you might want to use Spring STS Plugin if you are using Eclipse.

If you are able to have your GWT project a "Spring nature" then on your GWT RPC code, you can apply the standard Spring codes, i.e
in your ServiceImpl code you can override:

@Override
public void init() ...
{
 super.init();
 WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
 // Beans
 dao = (MyDao)ctx.getBean("myDao");
}

@Override
public void doSomething() {
 String something = dao.getSomething(...);
}

From here, you can use the beans to do something your app need to accomplish.

Of course you should fix your applicationContext.xml and web.xml which you can easily search the web on how to do this.

This is just the basic way to integrate GWT and Spring, as the topic is very broad, you can integrate other complex things like Spring authentication etc.

Hope this helps.
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
Akram MONCER
Personne

Filippo De Luca

unread,
Mar 9, 2012, 10:19:55 AM3/9/12
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Usually I implement the Service interface in a Spring bean, and I write the RemoteServlet implementation delegating all method to the Spring bean. Because the servlet is outside Spring transactional demarcation. You an also use threadlocal to pass request and response to the Spring bean (as GWT do).


On Friday, March 9, 2012 3:33:19 AM UTC, Xybrek wrote:
On 3/8/2012 11:33 PM, Akram Moncer wrote:
> hello everybody;
>
> can some one help me and give me how can i create webapp with spring
> framwork on back-end and GWT on front-end ?
>
> --
> Akram MONCER
> Personne
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To post to this group, send email to
> google-web-toolkit@googlegroups.com.

> To unsubscribe from this group, send email to
> google-web-toolkit+unsub...@googlegroups.com.

Akram Moncer

unread,
Mar 9, 2012, 2:27:36 PM3/9/12
to google-we...@googlegroups.com
@Filippo De Luca
i undersand what u mean but i'm a beginner in dévloppment so can u
give me a tutorial or a video that can show me how can i exactelly do
to integrate spring and GWT , thinks.

2012/3/9, Filippo De Luca <filosg...@gmail.com>:


> Usually I implement the Service interface in a Spring bean, and I write the
> RemoteServlet implementation delegating all method to the Spring bean.
> Because the servlet is outside Spring transactional demarcation. You an
> also use threadlocal to pass request and response to the Spring bean (as
> GWT do).
>
> On Friday, March 9, 2012 3:33:19 AM UTC, Xybrek wrote:
>>
>> On 3/8/2012 11:33 PM, Akram Moncer wrote:
>> > hello everybody;
>> >
>> > can some one help me and give me how can i create webapp with spring
>> > framwork on back-end and GWT on front-end ?
>> >
>> > --
>> > Akram MONCER
>> > Personne
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Google Web Toolkit" group.
>> > To post to this group, send email to

>> > google-we...@googlegroups.com.


>> > To unsubscribe from this group, send email to

>> > google-web-tool...@googlegroups.com.

> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/_fMVfXDgoaoJ.
> To post to this group, send email to google-we...@googlegroups.com.


> To unsubscribe from this group, send email to

> google-web-tool...@googlegroups.com.


> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


--
Akram MONCER
Personne

dodo dard

unread,
Mar 12, 2012, 4:57:47 AM3/12/12
to Google Web Toolkit
Hi,

You can also try this framework, I never had a change to use it, but a
friend of mine already used and its works pretty well :

http://code.google.com/p/spring4gwt/




==============
http://www.html5bydemo.com/

On Mar 9, 8:27 pm, Akram Moncer <akram.mon...@gmail.com> wrote:
> @Filippo De Luca
> i undersand what u mean but i'm a beginner in dévloppment so can u
> give me a tutorial or a video that can show me how can i exactelly do
> to integrate spring and GWT , thinks.
>
> 2012/3/9, Filippo De Luca <filosgang...@gmail.com>:

Alex Dobjanschi

unread,
Mar 13, 2012, 4:59:49 AM3/13/12
to google-we...@googlegroups.com
The framework is very elementary, and lacks one of spring's most important feature: ioc container.

Joseph Lust

unread,
Mar 13, 2012, 12:07:06 PM3/13/12
to google-we...@googlegroups.com
We've been using Spring4GWT to great effect in our enterprise application for the last year. While it may not include every aspect of Spring, it makes RPC's trivially easy. To review:

  • Make a Spring Bean as you normally would for a backend service, implementing your service interface and extending RemoteServiceServlet
  • Annotate the service, i.e. @Service("myService")
  • Annotate the service interface with the path of your servlet. i.e. @RemoteServiceRelativePath("springGwtServices/myService")
  • Make a servlet to handle your service (same path as above) in your web.xml. i.e. 
    <servlet>
        <servlet-name>springGwt</servlet-name>
        <servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>springGwt</servlet-name>
        <url-pattern>/com.myapp.myModule/springGwtServices/*</url-pattern>
    </servlet-mapping>
  • Make sure your async interface (for the RPC's) implements your service interface's methods.
  • Finally, in your client side code, just call your service's methods. i.e. MyServiceImpl.Default.getInstance().myRemoveMethod()
Most of the above steps need only be done once per module or service. If you use the ContainerDTO design pattern for sending data to the client, you need only change the ContainerDTO to send more or less data to the client. If you want to add a new remote method to call, you just need to update the service interface and add the method to the service. You never need to write any packing/unpacking code or any XHR code.

Having done this sort of thing by hand (XHR handlers in JS, serialization/deserialization, service MVC handling on the server in PHP/C#/or Java/Struts), this way of doing things is far easier, and you can unit test every bit of it easily in JUnit.


Sincerely,
Joe
Reply all
Reply to author
Forward
0 new messages