Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Crash ao abrir heroku

Segue o log:

2017-05-18T21:42:32.675088+00:00 app[web.1]: May 18, 2017 9:42:32 PM org.apache.catalina.startup.ContextConfig processAnnotationsJar
2017-05-18T21:42:32.675109+00:00 app[web.1]: SEVERE: Unable to process Jar entry [org/springframework/web/bind/annotation/support/HandlerMethodResolver.class] from Jar [jar:jndi:/localhost/WEB-INF/lib/spring-web-4.3.8.RELEASE.jar!/] for annotations
2017-05-18T21:42:32.675110+00:00 app[web.1]: java.io.EOFException
2017-05-18T21:42:32.675111+00:00 app[web.1]:    at org.apache.tomcat.util.bcel.classfile.FastDataInputStream.readInt(FastDataInputStream.java:145)
2017-05-18T21:42:32.675111+00:00 app[web.1]:    at org.apache.tomcat.util.bcel.classfile.ClassParser.readID(ClassParser.java:200)
2017-05-18T21:42:32.675112+00:00 app[web.1]:    at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:78)
2017-05-18T21:42:32.675113+00:00 app[web.1]:    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2071)
2017-05-18T21:42:32.675113+00:00 app[web.1]:    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1947)
2017-05-18T21:42:32.675114+00:00 app[web.1]:    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1913)
2017-05-18T21:42:32.675114+00:00 app[web.1]:    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1898)
2017-05-18T21:42:32.675116+00:00 app[web.1]:    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
2017-05-18T21:42:32.675115+00:00 app[web.1]:    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1330)
2017-05-18T21:42:32.675116+00:00 app[web.1]:    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
2017-05-18T21:42:32.675117+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
2017-05-18T21:42:32.675118+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
2017-05-18T21:42:32.675118+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5380)
2017-05-18T21:42:32.675119+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
2017-05-18T21:42:32.675120+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
2017-05-18T21:42:32.675121+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
2017-05-18T21:42:32.675122+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2017-05-18T21:42:32.675122+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2017-05-18T21:42:32.675123+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2017-05-18T21:42:32.675124+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)
2017-05-18T21:42:32.675125+00:00 app[web.1]:
2017-05-18T21:42:36.297834+00:00 app[web.1]: May 18, 2017 9:42:36 PM org.apache.catalina.core.ApplicationContext log
2017-05-18T21:42:36.297852+00:00 app[web.1]: INFO: 2 Spring WebApplicationInitializers detected on classpath
2017-05-18T21:42:36.374876+00:00 app[web.1]: log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
2017-05-18T21:42:36.374961+00:00 app[web.1]: log4j:WARN Please initialize the log4j system properly.
2017-05-18T21:42:36.375082+00:00 app[web.1]: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2017-05-18T21:42:36.451114+00:00 app[web.1]: May 18, 2017 9:42:36 PM org.apache.catalina.core.ApplicationContext log
2017-05-18T21:42:36.451119+00:00 app[web.1]: INFO: Initializing Spring root WebApplicationContext
2017-05-18T21:42:39.949322+00:00 app[web.1]: May 18, 2017 9:42:39 PM org.apache.catalina.core.StandardContext listenerStart
2017-05-18T21:42:39.949333+00:00 app[web.1]: SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
2017-05-18T21:42:39.949334+00:00 app[web.1]: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in br.com.casadocodigo.loja.conf.JPAConfiguration: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'java.util.Properties' available: expected single matching bean but found 2: additionalProperties,systemProperties
2017-05-18T21:42:39.949335+00:00 app[web.1]:    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
2017-05-18T21:42:39.949336+00:00 app[web.1]:    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
2017-05-18T21:42:39.949337+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
2017-05-18T21:42:39.949337+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
2017-05-18T21:42:39.949338+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
2017-05-18T21:42:39.949339+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
2017-05-18T21:42:39.949340+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
2017-05-18T21:42:39.949341+00:00 app[web.1]:    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
2017-05-18T21:42:39.949341+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
2017-05-18T21:42:39.949342+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
2017-05-18T21:42:39.949343+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
2017-05-18T21:42:39.949343+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
2017-05-18T21:42:39.949344+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
2017-05-18T21:42:39.949344+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
2017-05-18T21:42:39.949345+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
2017-05-18T21:42:39.949346+00:00 app[web.1]:    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
2017-05-18T21:42:39.949347+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)
2017-05-18T21:42:39.949348+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
2017-05-18T21:42:39.949348+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
2017-05-18T21:42:39.949349+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
2017-05-18T21:42:39.949350+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
2017-05-18T21:42:39.949350+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2017-05-18T21:42:39.949351+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2017-05-18T21:42:39.949352+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2017-05-18T21:42:39.949353+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)
2017-05-18T21:42:39.949354+00:00 app[web.1]: Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'java.util.Properties' available: expected single matching bean but found 2: additionalProperties,systemProperties
2017-05-18T21:42:39.949354+00:00 app[web.1]:    at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:173)
2017-05-18T21:42:39.949355+00:00 app[web.1]:    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
2017-05-18T21:42:39.949356+00:00 app[web.1]:    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
2017-05-18T21:42:39.949356+00:00 app[web.1]:    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
2017-05-18T21:42:39.949362+00:00 app[web.1]:    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
2017-05-18T21:42:39.949363+00:00 app[web.1]:    ... 24 more
2017-05-18T21:42:39.949364+00:00 app[web.1]:
2017-05-18T21:42:39.949863+00:00 app[web.1]: May 18, 2017 9:42:39 PM org.apache.catalina.core.StandardContext startInternal
2017-05-18T21:42:39.949864+00:00 app[web.1]: SEVERE: Error listenerStart
2017-05-18T21:42:39.999594+00:00 app[web.1]: May 18, 2017 9:42:39 PM org.apache.catalina.core.StandardContext startInternal
2017-05-18T21:42:39.999597+00:00 app[web.1]: SEVERE: Context [] startup failed due to previous errors
2017-05-18T21:42:40.001260+00:00 app[web.1]: SEVERE: Context [] failed in [org.apache.catalina.core.StandardContext] lifecycle. Allowing Tomcat to shutdown.
2017-05-18T21:42:40.002898+00:00 app[web.1]: May 18, 2017 9:42:40 PM org.apache.catalina.core.ApplicationContext log
2017-05-18T21:42:40.002900+00:00 app[web.1]: INFO: Closing Spring root WebApplicationContext
2017-05-18T21:42:40.013906+00:00 app[web.1]: May 18, 2017 9:42:40 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
2017-05-18T21:42:40.013909+00:00 app[web.1]: SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2017-05-18T21:42:40.018241+00:00 app[web.1]: May 18, 2017 9:42:40 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
2017-05-18T21:42:40.018243+00:00 app[web.1]: SEVERE: The web application [] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2017-05-18T21:42:40.041628+00:00 app[web.1]: May 18, 2017 9:42:40 PM org.apache.coyote.AbstractProtocol start
2017-05-18T21:42:40.041631+00:00 app[web.1]: INFO: Starting ProtocolHandler ["http-nio-4447"]
2017-05-18T21:42:40.072306+00:00 app[web.1]: May 18, 2017 9:42:40 PM org.apache.coyote.AbstractProtocol pause
2017-05-18T21:42:40.072309+00:00 app[web.1]: INFO: Pausing ProtocolHandler ["http-nio-4447"]
2017-05-18T21:42:40.821440+00:00 heroku[web.1]: State changed from up to crashed
2017-05-18T21:42:40.806134+00:00 heroku[web.1]: Process exited with status 0

JPAProductionConfiguration

@Profile("prod")
public class JPAProductionConfiguration {

    @Autowired
    private Environment environment;

    @Bean
    public Properties additionalProperties() {
        Properties props = new Properties();
        props.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
        props.setProperty("hibernate.show_sql", "true");
        props.setProperty("hibernate.hbm2ddl.auto", "update");
        return props;
    }

    @Bean
    public DataSource dataSource() throws URISyntaxException {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("org.postgresql.Driver");
        // usuario:senha@host:port/path
        URI dbUrl = new URI(environment.getProperty("DATABASE_URL"));

        dataSource.setUrl("jdbc:postgresql://"+dbUrl.getHost()
            +":"+dbUrl.getPort()+dbUrl.getPath());
        dataSource.setUsername(dbUrl.getUserInfo().split(":")[0]);
        dataSource.setPassword(dbUrl.getUserInfo().split(":")[1]);

        return dataSource;
    }

}

ServletSpringMVC

public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SecurityConfiguration.class, 
                AppWebConfiguration.class, JPAConfiguration.class,
                JPAProductionConfiguration.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] {};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] {"/"};
    }

    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
        encodingFilter.setEncoding("UTF-8");

        return new Filter[] {encodingFilter, new OpenEntityManagerInViewFilter()};
    }

    @Override
    protected void customizeRegistration(Dynamic registration) {
        registration.setMultipartConfig(new MultipartConfigElement(""));
    }

//    @Override
//    public void onStartup(ServletContext servletContext) throws ServletException {
//        super.onStartup(servletContext);
//        servletContext.addListener(RequestContextListener.class);
//        servletContext.setInitParameter("spring.profiles.active", "dev");
//    }

}

Procfile

web: java $JAVA_OPTS -jar -Dspring.profiles.active=prod target/dependency/webapp-runner.jar --port $PORT target/*.war

Eu ja subistitui o procfile pelo arquivo fonte do curso e ainda da esse erro, o que pode ser?

2 respostas

Olá Rodrigo,

O problema está no treecho de código abaixo, você deve remover a anotação @Bean desse método, pois caso contrário você estará dizendo ao spring que esse método é um factory para criar objetos Properties, porém nativamente o spring já possui um factory para isso, o erro diz exatamente isso, o spring encontrou duas formas de criar o mesmo objeto e não sabe qual deles usar.

    @Bean
    public Properties additionalProperties() {
        Properties props = new Properties();
        props.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
        props.setProperty("hibernate.show_sql", "true");
        props.setProperty("hibernate.hbm2ddl.auto", "update");
        return props;
    }

Para fazer a configuração que você deseja, você poderia deixar o código do seu factory do datasource parecido com o abaixo:

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(){
        LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        factoryBean.setJpaVendorAdapter(vendorAdapter);

        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        //nao precisa colocar a porta pois estamos utilizando a default
        dataSource.setUrl("jdbc:mysql://localhost/casadocodigo");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");

        factoryBean.setDataSource(dataSource);

        Properties props= new Properties();
        props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
        props.setProperty("hibernate.show_sql", "true");
        props.setProperty("hibernate.hbm2ddl.auto", "update");

        factoryBean.setJpaProperties(props);
        factoryBean.setPackagesToScan("br.com.alura.loja.model");
        return factoryBean;
    }
solução!

Entendi o que você quis dizer sobre o erro. Não tinha prestado atenção no erro.

Mas no curso o instrutor ensina a colocar desta forma e o dele roda!

Teoricamente esta linha "-Dspring.profiles.active=prod" mostra que é para usar o profile prod e desconsiderar o resto.

Onde que o spring está puxando esse "systemProperties" ?


No final da aula o instrutor avisou que precisa ativar o Free Dynos, o mais bizarro, é que por mais cansado que eu estivesse ontem eu sei que fiz isso. Eu lembro de ter ido e colocado o botão em ON. Porque ele voltou à off eu não sei.

Bom caso alguém caia no mesmo problema que eu.

expected single matching bean but found 2: additionalProperties,systemProperties

É por causa que o Dynos não esta ativo e então o Procfile não está sendo executado (pelo menos é isso que eu entendi).

É preciso abrir a pasta do app criado e em overview ir em: Configure Dynos;

Ali no lado direito tem um icone de lapis e clicando nele tem como alterar para "ON" e confirmar para ativar o Dynos.

Não sei se quando eu fiz o upload do projeto ele jogou para off ou o que eu fiz, mas é bom dar uma segunda checada nessa configuração.


Obrigado Denis Ricci, por me apontar o problema do log!