Quando aperto o botão enviar no formulário da um NullPointerException, a pilha indica a execeção iniciada em ContaDAO.java:35, onde é feita a preparação da query de inserção dentro do método adiciona, será que o problema esta no arquivo spring-context.xml?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="br.com.caelum.contas" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id= "conversionService" class= "org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class= "br.com.caelum.contas.StringToEnumConverterFactory" />
</list>
</property>
</bean>
</beans>
Segue também o controller
package br.com.caelum.contas.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import br.com.caelum.contas.dao.ContaDAO;
import br.com.caelum.contas.modelo.Conta;
@Controller
public class ContaController {
@RequestMapping("/form")
public String formulario(){
return "formulario";
}
@RequestMapping("/adicionaConta")
public String action(Conta conta){
ContaDAO dao = new ContaDAO();
dao.adiciona(conta);
return "conta-adicionada";
}
}
E o metodo adiciona de ContaDAO
public void adiciona(Conta conta) {
String sql = "insert into contas (descricao, paga, valor, tipo) values (?,?,?,?)";
PreparedStatement stmt;
try {
stmt = connection.prepareStatement(sql);
stmt.setString(1, conta.getDescricao());
stmt.setBoolean(2, conta.isPaga());
stmt.setDouble(3, conta.getValor());
stmt.setString(4, conta.getTipo().name());///A exception acontece aqui
stmt.execute();
connection.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
Obrigado!