3
respostas

Falhas ao conectar ao banco

Pessoal, eu estou fazendo um trabalho semelhante ao que se apresenta aqui. Só que eu não consigo conectar ao banco. Vou passar os codigos:


2018-06-18 10:21:11.512  INFO 7509 --- [           main] br.com.jp.Conf                           : Starting Conf on vinicius-VPCEG17FB with PID 7509 (/home/vinicius/workspace/prova-semob/target/classes started by vinicius in /home/vinicius/workspace/prova-semob)
2018-06-18 10:21:11.520  INFO 7509 --- [           main] br.com.jp.Conf                           : No active profile set, falling back to default profiles: default
2018-06-18 10:21:11.990  INFO 7509 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@708f5957: startup date [Mon Jun 18 10:21:11 BRT 2018]; root of context hierarchy
2018-06-18 10:21:14.686  INFO 7509 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$6d1f69a0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-06-18 10:21:15.514  INFO 7509 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-06-18 10:21:15.537  INFO 7509 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2018-06-18 10:21:15.539  INFO 7509 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.5
2018-06-18 10:21:15.915  INFO 7509 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-06-18 10:21:15.915  INFO 7509 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3944 ms
2018-06-18 10:21:16.136  INFO 7509 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-06-18 10:21:16.141  INFO 7509 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-06-18 10:21:16.142  INFO 7509 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-06-18 10:21:16.142  INFO 7509 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-06-18 10:21:16.142  INFO 7509 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-06-18 10:21:16.196  INFO 7509 --- [           main] o.s.j.d.DriverManagerDataSource          : Loaded JDBC driver: com.mysql.jdbc.Driver
2018-06-18 10:21:16.374  WARN 7509 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.setPersistenceUnitRootLocation(Ljava/lang/String;)V
2018-06-18 10:21:16.386  INFO 7509 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2018-06-18 10:21:16.416  INFO 7509 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-06-18 10:21:16.428 ERROR 7509 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframewor
3 respostas

É um sistema de apreensão, tipo DETRAN

package br.com.jp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import br.com.jp.model.Apreensao;
import br.com.jp.repository.ApreensaoRepository;

@Controller
public class ApreensaoController {

    @Autowired
    private ApreensaoRepository repo;

    @RequestMapping("cars")
    public String getCars(Model model) {
        Iterable<Apreensao> apreensoes = this.repo.findAll();
        model.addAttribute("apreensoes", apreensoes);
        return "listaCarros";
    }

    @RequestMapping("/")
    public String index() {
        return "index";
    }
}
package br.com.jp;

import javax.sql.DataSource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

@SpringBootApplication
public class Conf {

    public static void main(String[] args) {
        SpringApplication.run(Conf.class, args);
    }

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/semob");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        return dataSource;
    }
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Carros Apreendidos</title>
</head>
<body>
    <h1>carros</h1>
</body>
</html>

na pasta src/main/java eu tenho os pacotes: br.com.jp: Com as classes : Conf.Java e ApreensaoController.java

br.com.jp.model: Classes: Apreensao.java

br.com.jp.repository: Interface: ApreensaoRepository.

Alguém tem alguma ideia do que há?

Oi Marcos, a exception é importante aqui... eu ia falar que é estranho que a senha seja igual ao usuário, mas imagino que você configurou assim mesmo.

a senha e o usuario é root. Isso ta certo