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

Ajuda com publicação de Projeto

Segui todos os passos para a publicação do projeto de acordo o curso, porém meu projeto é diferente, mas segue as mesmas linhas de configuração, consigo postar no heroku e não me apresenta nenhum tipo de erro, porém não consigo acessar a aplicação. Alguém poderia me ajudar. segue o projeto no git

https://github.com/felipeferraz14/agendapsf

7 respostas

Oi Felipe, tudo bom?

Qual erro/O que ocorre quando você tenta acessar a aplicação? Você poderia compartilhar com a gente?

Aguardo retorno.

Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.

Não consigo encontrar algum log pra identificar o erro.

Quando dou o comando heroku log --tail me apresenta esses dois erros no projeto

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class br.com.agendapsf.conf.JPAConfiguration: Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.sql.DataSource]: : Error creating bean with name 'datasource' defined in class br.com.agendapsf.conf.JPAConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource br.com.agendapsf.conf.JPAConfiguration.datasource() throws java.net.URISyntaxException] threw exception; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource' defined in class br.com.agendapsf.conf.JPAConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource br.com.agendapsf.conf.JPAConfiguration.datasource() throws java.net.URISyntaxException] threw exception; nested exception is java.lang.NullPointerException

error creating bean with name 'datasource' defined in class br.com.agendapsf.conf.JPAConfiguration: Instatiation of bean failed; nested exception is org.springframework.nbeans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource br.com.agendapsf.conf.JPAConfiguration.datasource() throws java.net.URISyntaxException] threw exception;

minha classe JPA

package br.com.agendapsf.conf;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
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;

@EnableTransactionManagement
@Profile("prod")
public class JPAConfiguration {

    @Autowired
    private Environment environment;

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, Properties addProperties) throws URISyntaxException{
        LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();

        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        factoryBean.setJpaVendorAdapter(vendorAdapter);
        factoryBean.setDataSource(dataSource);

        factoryBean.setJpaProperties(addProperties);
        factoryBean.setPackagesToScan("br.com.agendapsf.models");

         return factoryBean;
    }

    @Bean
    public DataSource datasource() throws URISyntaxException {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("org.postgresql.Driver");

        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;
    }

    @Bean    
    public Properties addProperties() {
        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 JpaTransactionManager transactionManager(EntityManagerFactory emf){
        return new JpaTransactionManager(emf);

    }


}
solução!

Oi Felippe,

Tenta dar uma olhada na forma com que você está processando essa URL:

        URI dbUrl = new URI(environment.getProperty("DATABASE_URL"));

O erro que você está recebendo costuma estar relacionado com problemas na leitura da URL.

Só mais uma pergunta. Seu sistema está funcionando normal localmente? Ou o problema é só no heroku?

Abraço!

Opa, ali ta acusando um NPE, só debugando para ver o que ta acontecendo. Não falou a linha do npe, mas acho que André tem razão.

verificando a documentação do heroku consegui mudar a URI e agora o erro que me apresenta é esse:

remote:        Released v11
remote:        https://agendapsf.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/agendapsf.git
   28a7c38..ff74e99  master -> master

C:\Users\Felipe\Documents\forge\bin\agendapsf>git add .

C:\Users\Felipe\Documents\forge\bin\agendapsf>git commit -m "configurações do banco"
[master 0df5338] configurações do banco
 4 files changed, 4 insertions(+), 7 deletions(-)
 rewrite target/classes/br/com/agendapsf/conf/JPAProductionConfiguration.class (67%)

C:\Users\Felipe\Documents\forge\bin\agendapsf>git push heroku master
Counting objects: 19, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (19/19), 3.03 KiB | 0 bytes/s, done.
Total 19 (delta 6), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Java app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Installing Maven 3.3.9... done
remote: -----> Executing: mvn -B -DskipTests clean dependency:list install
remote:        [INFO] Scanning for projects...
remote:        [INFO]
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] Building agendapsf 1.0.0-SNAPSHOT
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO]
remote:        [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ agendapsf ---
remote:        [INFO] Deleting /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/target
remote:        [INFO]
remote:        [INFO] --- maven-dependency-plugin:2.3:list (default-cli) @ agendapsf ---
remote:        [INFO]
remote:        [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ agendapsf ---
remote:        [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote:        [INFO] skip non existing resourceDirectory /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/resources
remote:        [INFO]
remote:        [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ agendapsf ---
remote:        [INFO] Changes detected - recompiling the module!
remote:        [INFO] Compiling 29 source files to /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/target/classes
remote:        [WARNING] /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/java/br/com/agendapsf/conf/SecutiryConfiguration.java: /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/java/br/com/agendapsf/conf/SecutiryConfiguration.java uses or overrides a deprecated API.
remote:        [WARNING] /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/java/br/com/agendapsf/conf/SecutiryConfiguration.java: Recompile with -Xlint:deprecation for details.
remote:        [WARNING] /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/java/br/com/agendapsf/daos/UsuarioDAO.java: /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/java/br/com/agendapsf/daos/UsuarioDAO.java uses unchecked or unsafe operations.
remote:        [WARNING] /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/java/br/com/agendapsf/daos/UsuarioDAO.java: Recompile with -Xlint:unchecked for details.
remote:        [INFO]
remote:        [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ agendapsf ---
remote:        [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote:        [INFO] skip non existing resourceDirectory /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/test/resources
remote:        [INFO]
remote:        [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ agendapsf ---
remote:        [INFO] No sources to compile
remote:        [INFO]
remote:        [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ agendapsf ---
remote:        [INFO] Tests are skipped.
remote:        [INFO]
remote:        [INFO] --- maven-war-plugin:2.6:war (default-war) @ agendapsf ---
remote:        [INFO] Packaging webapp
remote:        [INFO] Assembling webapp [agendapsf] in [/tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/target/agendapsf]
remote:        [INFO] Processing war project
remote:        [INFO] Copying webapp resources [/tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/src/main/webapp]
remote:        [INFO] Webapp assembled in [319 msecs]
remote:        [INFO] Building war: /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/target/agendapsf.war
remote:        [INFO]
remote:        [INFO] --- maven-dependency-plugin:2.3:copy (default) @ agendapsf ---
remote:        [INFO] Configured Artifact: com.github.jsimone:webapp-runner:8.5.5.0:jar
remote:        [INFO] Copying webapp-runner-8.5.5.0.jar to /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/target/dependency/webapp-runner.jar
remote:        [INFO]
remote:        [INFO] --- maven-install-plugin:2.4:install (default-install) @ agendapsf ---
remote:        [INFO] Installing /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/target/agendapsf.war to /app/tmp/cache/.m2/repository/org/agendapsf/agendapsf/1.0.0-SNAPSHOT/agendapsf-1.0.0-SNAPSHOT.war
remote:        [INFO] Installing /tmp/build_6bb80dfef7b69ecf93b0d8a82f2053e5/pom.xml to /app/tmp/cache/.m2/repository/org/agendapsf/agendapsf/1.0.0-SNAPSHOT/agendapsf-1.0.0-SNAPSHOT.pom
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] BUILD SUCCESS
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] Total time: 6.290 s
remote:        [INFO] Finished at: 2017-01-09T22:24:01+00:00
remote:        [INFO] Final Memory: 25M/206M
remote:        [INFO] ------------------------------------------------------------------------
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 102.1M
remote: -----> Launching...
remote:        Released v12
remote:        https://agendapsf.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/agendapsf.git
   ff74e99..0df5338  master -> master

C:\Users\Felipe\Documents\forge\bin\agendapsf>heroku logs --tail
2017-01-09T22:24:23.968979+00:00 app[web.1]: Jan 09, 2017 10:24:23 PM org.apache.catalina.core.StandardService startInternal
2017-01-09T22:24:24.220669+00:00 app[web.1]: Jan 09, 2017 10:24:24 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
2017-01-09T22:24:24.220688+00:00 app[web.1]: INFO: No global web.xml found
2017-01-09T22:24:24.914074+00:00 heroku[web.1]: State changed from starting to up
2017-01-09T22:24:27.405039+00:00 app[web.1]: Jan 09, 2017 10:24:27 PM org.apache.jasper.servlet.TldScanner scanJars
2017-01-09T22:24:27.405054+00:00 app[web.1]: INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2017-01-09T22:24:27.481491+00:00 app[web.1]: Jan 09, 2017 10:24:27 PM org.apache.catalina.core.ApplicationContext log
2017-01-09T22:24:27.481495+00:00 app[web.1]: INFO: Spring WebApplicationInitializers detected on classpath: [br.com.agendapsf.conf.SpringSecurityFilterConfiguration@7c645fd1, br.com.agendapsf.conf.ServletSpringMVC@14b74ae0]
2017-01-09T22:24:27.561092+00:00 app[web.1]: log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
2017-01-09T22:24:27.561135+00:00 app[web.1]: log4j:WARN Please initialize the log4j system properly.
2017-01-09T22:24:27.561156+00:00 app[web.1]: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2017-01-09T22:24:27.673894+00:00 app[web.1]: Jan 09, 2017 10:24:27 PM org.apache.catalina.core.ApplicationContext log
2017-01-09T22:24:27.673911+00:00 app[web.1]: INFO: Initializing Spring root WebApplicationContext
2017-01-09T22:24:28.413935+00:00 app[web.1]: SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
2017-01-09T22:24:28.413940+00:00 app[web.1]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'secutiryConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.agendapsf.daos.LoginDAO br.com.agendapsf.conf.SecutiryConfiguration.usuarioDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined
2017-01-09T22:24:28.413941+00:00 app[web.1]:    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:326)
2017-01-09T22:24:28.413942+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)
2017-01-09T22:24:28.413907+00:00 app[web.1]: Jan 09, 2017 10:24:28 PM org.apache.catalina.core.StandardContext listenerStart
2017-01-09T22:24:28.413943+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
2017-01-09T22:24:28.413944+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
2017-01-09T22:24:28.413943+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
2017-01-09T22:24:28.413946+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
2017-01-09T22:24:28.413946+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
2017-01-09T22:24:28.413948+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
2017-01-09T22:24:28.413947+00:00 app[web.1]:    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
2017-01-09T22:24:28.413948+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
2017-01-09T22:24:28.413945+00:00 app[web.1]:    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
2017-01-09T22:24:28.413950+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
2017-01-09T22:24:28.413951+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4725)
2017-01-09T22:24:28.413952+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
2017-01-09T22:24:28.413953+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
2017-01-09T22:24:28.413953+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
2017-01-09T22:24:28.413949+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
2017-01-09T22:24:28.413950+00:00 app[web.1]:    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
2017-01-09T22:24:28.413952+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
2017-01-09T22:24:28.413955+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2017-01-09T22:24:28.413956+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2017-01-09T22:24:28.413954+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2017-01-09T22:24:28.413957+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)
2017-01-09T22:24:28.413958+00:00 app[web.1]: Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.agendapsf.daos.LoginDAO br.com.agendapsf.conf.SecutiryConfiguration.usuarioDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined
2017-01-09T22:24:28.413960+00:00 app[web.1]:    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
2017-01-09T22:24:28.413966+00:00 app[web.1]:    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:323)
2017-01-09T22:24:28.413968+00:00 app[web.1]:    ... 22 more
2017-01-09T22:24:28.413959+00:00 app[web.1]:    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:542)
2017-01-09T22:24:28.413969+00:00 app[web.1]:    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:356)
2017-01-09T22:24:28.413969+00:00 app[web.1]: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined
2017-01-09T22:24:28.413970+00:00 app[web.1]:    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)