Monday, March 4, 2013

Re: NullPoniter when calling the DAO object (@Autowired) - GWT and Spring problem integration



On Monday, March 4, 2013 5:48:12 PM UTC+1, Borja Gonzalez wrote:
Hi, im writting the code for a console using GWT and Spring integration. I have followed GWT tutorial and read some forums about how to use spring qith GWT.

I'm at the point that the RPC call is returning null and i can't seem to see why. As english is not my native language and i'm pretty new to this, I'm just going to put my code here to see if someone can help me with it.


[b]Service:[/b]
[code=java]
@RemoteServiceRelativePath("GestionUserService")
public interface GestionUserService extends RemoteService {
Collection<Usuario> dameTablaUsuarios(String entidad);

}
[/code]

[b]Async:[/b]
[code=java]
public interface GestionUserServiceAsync {
void dameTablaUsuarios(String entidad,AsyncCallback<Collection<Usuario>> callback);

}
[/code]

[b]Impl:[/b]
[code=java]
@SuppressWarnings("serial")
@Service("GestionUserService")
public class GestionUsersConsultImpl extends RemoteServiceServlet implements GestionUserService {
@Autowired
UserConsoleDBUtil utilDB;
Logger logger = Logger.getLogger(GestionUsersConsultImpl.class);
@SuppressWarnings("unchecked")
public Collection<Usuario> dameTablaUsuarios(String entidad) {
GWT.log("Log");
logger.info("He llegado al IMPL dameTablaUsuarios.======================="+entidad);
logger.info("UtilDB "+utilDB.toString());
return utilDB.getDao().getUsuarios(entidad);
}
}
[/code]

[b]*gwt.xml:[/b]
[code=xml]
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='userConsole'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />

<!-- Compilar solamente para Firefox -->
<!--<set-property name="user.agent" value="gecko1_8"></set-property> -->

<inherits name='com.google.gwt.user.theme.standard.Standard' />
<inherits name="com.google.gwt.i18n.I18N" />

<!-- Specify the app entry point class. -->
<entry-point class='com.santander.bam.comun.userconsole.client.GestionUsers' />


<!-- English language, independent of country -->
<extend-property name="locale" values="es_ES" />
<extend-property name="locale" values="en_US" />
<extend-property name="locale" values="de_DE" />

<!-- Specify the application specific style sheet. -->
<stylesheet src='UserConsole.css' />

<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='client/services' />
<source path='db/bean' />
</module>
[/code]

[b]applicationContext.xml:[/b]
[code=xml]
xsi:schemaLocation="

<!--  Agregado de la consola gwt-spring -->

<!-- Activates scanning of @Autowired -->
<context:annotation-config />
<context:component-scan base-package="com.santander.bam.comun.userconsole" />

<!--  FIN Agregado de la consola gwt-spring -->

<import resource="config.xml" />
<util:constant id="VARCHAR" static-field="java.sql.Types.VARCHAR" />
    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="myDataSource"/>
  </bean>
<bean id="GestionUserService" class="com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl"></bean>
<bean id="utilDB" class="com.santander.bam.comun.userconsole.db.UserConsoleDBUtil">
<property name="dao" ref="UserConsoleDAO" />
<property name="transactionManager" ref="transactionManager"/>
</bean>
 
</beans>[/code]

[b]config.xml[/b]
xsi:schemaLocation="


<bean id="UserConsoleDAO" class="com.santander.bam.comun.userconsole.db.UserConsoleDAO">
<property name="dataSource" ref="myDataSource" />

<!-- Definicion de consultas -->
<property name="sqlUsuarios"
value=" SELECT DISTINCT (IDUSER) IDUser,
   NOMBRE Nombre,
   IDPerfil IDPerfil,
   FECHAALTA FechaAlta,
   FECHABAM FechaBAM,
   FECHACON FechaConsola
FROM
   A_APAMA.USERS
WHERE
   EMPRESA=?" />
   
<property name="sqlUsuarios2"
value=" SELECT DISTINCT (IDUSER) IDUser
FROM
   A_APAMA.USERS
WHERE
   EMPRESA=?" />
</bean>

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" />
<property name="url"
value="jdbc:db2://udisapma.isban.dev.corp:60090/udisapma" />
<property name="username" value="a_apama" />
<property name="password" value="********" />
</bean>

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="myDataSource" />
</bean>
</beans>[/code]

And finally my [b]web.xml[/b]:
[code=java]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<!-- Loads and makes available the context defined in springconfig-service.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>gestionUsersConsultImpl</servlet-name>
<servlet-class>com.santander.bam.comun.userconsole.server.GestionUsersConsultImpl</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<url-pattern>/springGwtServices/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>gestionUsersConsultImpl</servlet-name>
<url-pattern>/userConsole/GestionUserService</url-pattern>
</servlet-mapping>

This servlet is created by your servlet container, not by Spring, so it won't have its dependencies injected by Spring.
Try mapping the springgwtRemoteServiceServlet to that <url-pattern>.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment