Informações: Loading application [novo] at [/novo]
Informações: novo was successfully deployed in 6.036 milliseconds.
Informações: ESTA É A HOME DA EDFRANGOS.
Informações: Opcao{nomeOpcao=nada, somaOuDiminui=s}
Advertência: StandardWrapperValve[dispatcher]: Servlet.service() for servlet dispatcher threw exception
java.lang.NullPointerException
package br.com.novo.edfrangos.daos;
import br.com.novo.edfrangos.models.Opcao;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional
public class OpcaoDAO {
@PersistenceContext
private EntityManager manager;
public void gravar(Opcao opcao) {
manager.persist(opcao);
}
}
package br.com.novo.edfrangos.conf;
import javax.persistence.EntityManagerFactory;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.util.Properties;
@EnableTransactionManagement
public class JPAConfiguration {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factoryBean
= new LocalContainerEntityManagerFactoryBean();
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
factoryBean.setJpaVendorAdapter(vendorAdapter);
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUsername("postgres");
dataSource.setPassword("123456");
dataSource.setUrl("jdbc:postgresql://localhost:5432/edfrangos");
dataSource.setDriverClassName("org.postgresql.Driver");
factoryBean.setJtaDataSource(dataSource);
Properties props = new Properties();
props.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
props.setProperty("hibernate.show_sql", "true");
props.setProperty("hibernate.hbm2ddl.auto", "update");
factoryBean.setJpaProperties(props);
factoryBean.setPackagesToScan("br.com.novo.edfrangos.models");
return factoryBean;
}
@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
}
package br.com.novo.edfrangos.controllers;
import br.com.novo.edfrangos.daos.OpcaoDAO;
import br.com.novo.edfrangos.models.Opcao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class OpcaoController {
@Autowired
private OpcaoDAO opcaoDAO;
@RequestMapping("/opcao/form")
public String form() {
return "opcao/form";
}
@RequestMapping("/opcao")
public String gravar(Opcao opcao) {
System.out.println(opcao);
opcaoDAO.gravar(opcao);
return "opcao/ok";
}
}
package br.com.novo.edfrangos.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String index() {
System.out.println("ESTA É A HOME DA EDFRANGOS.");
return "home";
}
}
package br.com.novo.edfrangos.conf;
import br.com.novo.edfrangos.controllers.HomeController;
import br.com.novo.edfrangos.daos.OpcaoDAO;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@EnableWebMvc
@ComponentScan(basePackageClasses = {HomeController.class, OpcaoDAO.class})
public class AppWebConfiguration {
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}