3
respostas

Não consigo setar o banco

Vejam os erros:

    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.dataSource(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao.dataSource(Configuracao.java:27) [classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.CGLIB$dataSource$0(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1$$FastClassBySpringCGLIB$$13b13dbf.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.dataSource(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao.dataSource(Configuracao.java:27) [classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.CGLIB$dataSource$0(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1$$FastClassBySpringCGLIB$$13b13dbf.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.dataSource(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao.dataSource(Configuracao.java:27) [classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.CGLIB$dataSource$0(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1$$FastClassBySpringCGLIB$$13b13dbf.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.dataSource(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao.dataSource(Configuracao.java:27) [classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.CGLIB$dataSource$0(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1$$FastClassBySpringCGLIB$$13b13dbf.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.dataSource(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao.dataSource(Configuracao.java:27) [classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.CGLIB$dataSource$0(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1$$FastClassBySpringCGLIB$$13b13dbf.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.dataSource(<generated>) ~[classes/:na]
    at br.com.jp.semob.Configuracao.dataSource(Configuracao.java:27) [classes/:na]
    at br.com.jp.semob.Configuracao$$EnhancerBySpringCGLIB$$2d595bb1.CGLIB$dataSource$0(<generated>) ~
package br.com.jp.semob;


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;
import org.springframework.stereotype.Controller;

@SpringBootApplication
@Controller
public class Configuracao {

    public static void main(String[] args) {
        SpringApplication.run(Configuracao.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();
    }
}
3 respostas

O banco já tem tabela populada. Tudo funcionava até eu tentar me conectar ao banco. Vi na net que era para fazer um application.properties. Fiz e nada adiantou. Outro disse que é para saber bem onde colocar os arquivos. Fazer bem os pacotes... Acho que seria bom no curso isso ser abordado.

Oi Marcos, realmente não é para ser complicado. O application.properties é explicado no curso de springboot, caso você prefira ir por esse caminho. De todo jeito, vamos tentar focar em resolver o seu problema.

Consegue colocar a pilha inteira da exception? Ta faltando informação :).

através de fóruns eu diminui a pilha. Adicionei no pom o seguinte:

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.2.3.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.4.Final</version>
        </dependency>

pilha de exception:


2018-06-18 16:44:02.559  INFO 4273 --- [           main] br.com.jp.Conf                           : Starting Conf on vinicius-VPCEG17FB with PID 4273 (/home/vinicius/workspace/prova-semob/target/classes started by vinicius in /home/vinicius/workspace/prova-semob)
2018-06-18 16:44:02.564  INFO 4273 --- [           main] br.com.jp.Conf                           : No active profile set, falling back to default profiles: default
2018-06-18 16:44:03.112  INFO 4273 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7722c3c3: startup date [Mon Jun 18 16:44:03 BRT 2018]; root of context hierarchy
2018-06-18 16:44:05.638  INFO 4273 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$86318451] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-06-18 16:44:06.491  INFO 4273 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-06-18 16:44:06.531  INFO 4273 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2018-06-18 16:44:06.533  INFO 4273 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.5
2018-06-18 16:44:06.742  INFO 4273 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-06-18 16:44:06.743  INFO 4273 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3640 ms
2018-06-18 16:44:07.023  INFO 4273 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-06-18 16:44:07.030  INFO 4273 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-06-18 16:44:07.030  INFO 4273 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-06-18 16:44:07.030  INFO 4273 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-06-18 16:44:07.031  INFO 4273 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-06-18 16:44:07.206  WARN 4273 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apreensaoController': Unsatisfied dependency expressed through field 'repo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apreensaoRepository': Cannot create inner bean '(inner bean)#558756be' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#558756be': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
2018-06-18 16:44:07.213  INFO 4273 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2018-06-18 16:44:07.243  WARN 4273 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2018-06-18 16:44:07.289  INFO 4273 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-06-18 16:44:07.422