When doing a query in a dao class, the following error appears:
My spring-context.xml is:
<mvc:interceptors>
<bean class="br.com.softwarescomerciais.os.interceptor.AutorizadorInterceptor"></bean>
</mvc:interceptors>
<mvc:default-servlet-handler/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.101.178/sc"/>
<property name="username" value="sfilho"/>
<property name="password" value="123"/>
</bean>
My class gives:
@Autowired
private DataSource dataSource;
public boolean existe(Usuario usuario) {
if (usuario == null) {
throw new IllegalArgumentException("Usuário não deve ser nulo");
}
String sql = "select NOME from USUARIOS where NOME = :NOME and SENHA = :SENHA";
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
Map<String, Object> parametros = new HashMap<String, Object>();
parametros.put("NOME", usuario.getNome());
parametros.put("SENHA", usuario.getSenha());
SqlRowSet srs = jdbcTemplate.queryForRowSet(sql, parametros);
boolean existe = srs.next();
return existe;
}
Error:
HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: DataSource must not be null
type Exception report
message Request processing failed; nested exception is java.lang.IllegalArgumentException: DataSource must not be null
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: DataSource must not be null org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:943) org.springframework.web.servlet.FrameworkServlet.doPost (FrameworkServlet.java:833) javax.servlet.http.HttpServlet.service (HttpServlet.java:648) org.springframework.web.servlet.FrameworkServlet.service (FrameworkServlet.java:807) javax.servlet.http.HttpServlet.service (HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:53) root cause
java.lang.IllegalArgumentException: DataSource must not be null org.springframework.util.Assert.notNull (Assert.java:112) org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate. (NamedParameterJdbcTemplate.java:89) br.softwarescomerciais.os.dao.UsuarioDao.existe (UserDao.java:27) br.com.softwarescomerciais.os.controller.LoginController.efetuaLogin (LoginController.java:34) sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source) java.lang.reflect.Method.invoke (Unknown Source) org.springframework.web.method.support.InvocableHandlerMethod.invoke (InvocableHandlerMethod.java:214) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest (InvocableHandlerMethod.java:132) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle (ServletInvocableHandlerMethod.java:104) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod (RequestMappingHandlerAdapter.java:748) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal (RequestMappingHandlerAdapter.java:689) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle (AbstractHandlerMethodAdapter.java:83) org.springframework.web.servlet.DispatcherServlet.doDispatch (DispatcherServlet.java:945) org.springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:876) org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:931) org.springframework.web.servlet.FrameworkServlet.doPost (FrameworkServlet.java:833) javax.servlet.http.HttpServlet.service (HttpServlet.java:648) org.springframework.web.servlet.FrameworkServlet.service (FrameworkServlet.java:807) javax.servlet.http.HttpServlet.service (HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:53)