Connect SpringBoot with PostgreSQL

1

I'm trying to connect the bank to SpringBoot and I'm finding that my problem is here:

# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
spring.datasource.url=jdbc:postgresql://localhost:5432/springbootdb?createDatabaseIfNotExist=true&useSSL=false
spring.datasource.username=postgres
spring.datasource.password=1234
spring.datasource.driver-class-name=org.postgresql.Driver

# ===============================
# = JPA / HIBERNATE
# ===============================
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update): with "create-drop" the database
# schema will be automatically created afresh for every start of application
spring.jpa.hibernate.ddl-auto=create-drop


# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

This is my pom.xml

Even the drive is installed as you can see:

<dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency> 

pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.wladimir</groupId>
    <artifactId>wladimir-api</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>wladimir-api</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency> 

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

This is my bank:

Iacceptsuggestions.

Thisistheerrormessage:

java.net.BindException:Addressalreadyinuse:bindatsun.nio.ch.Net.bind0(NativeMethod)~[na:1.8.0_151]atsun.nio.ch.Net.bind(UnknownSource)~[na:1.8.0_151]atsun.nio.ch.Net.bind(UnknownSource)~[na:1.8.0_151]atsun.nio.ch.ServerSocketChannelImpl.bind(UnknownSource)~[na:1.8.0_151]atsun.nio.ch.ServerSocketAdaptor.bind(UnknownSource)~[na:1.8.0_151]atorg.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210)~[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:990)~[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:635)~[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.apache.catalina.connector.Connector.startInternal(Connector.java:1022)[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.apache.catalina.core.StandardService.addConnector(StandardService.java:225)[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:250)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:193)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:303)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1118)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1107)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atcom.example.wladimir.money.WladimirApiApplication.main(WladimirApiApplication.java:10)[classes/:na]atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)~[na:1.8.0_151]atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)~[na:1.8.0_151]atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)~[na:1.8.0_151]atjava.lang.reflect.Method.invoke(UnknownSource)~[na:1.8.0_151]atorg.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[spring-boot-devtools-1.5.8.RELEASE.jar:1.5.8.RELEASE]2017-11-1315:51:20.037ERROR6092---[restartedMain]o.apache.catalina.core.StandardService:Failedtostartconnector[Connector[HTTP/1.1-8080]]org.apache.catalina.LifecycleException:Failedtostartcomponent[Connector[HTTP/1.1-8080]]atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)~[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.apache.catalina.core.StandardService.addConnector(StandardService.java:225)~[tomcat-embed-core-8.5.23.jar:8.5.23]atorg.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:250)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:193)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:303)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1118)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1107)[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]atcom.example.wladimir.money.WladimirApiApplication.main(WladimirApiApplication.java:10)[classes/:na]atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)~[na:1.8.0_151]atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)~[na:1.8.0_151]atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)~[na:1.8.0_151]atjava.lang.reflect.Method.invoke(UnknownSource)~[na:1.8.0_151]atorg.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[spring-boot-devtools-1.5.8.RELEASE.jar:1.5.8.RELEASE]Causedby:org.apache.catalina.LifecycleException:service.getName():"Tomcat";  Protocol handler start failed
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1031) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    ... 18 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_151]
    at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_151]
    at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_151]
    at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) ~[na:1.8.0_151]
    at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) ~[na:1.8.0_151]
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:990) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:635) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1022) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
    ... 19 common frames omitted

2017-11-13 15:51:20.045  INFO 6092 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2017-11-13 15:51:20.056  INFO 6092 --- [  restartedMain] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-11-13 15:51:20.066 ERROR 6092 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.

2017-11-13 15:51:20.067  INFO 6092 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@af31e4: startup date [Mon Nov 13 15:51:14 GMT-03:00 2017]; root of context hierarchy
2017-11-13 15:51:20.070  INFO 6092 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2017-11-13 15:51:20.071  INFO 6092 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-11-13 15:51:20.071  INFO 6092 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2017-11-13 15:51:20.072  INFO 6092 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
    
asked by anonymous 13.11.2017 / 19:46

1 answer

1

This error is not related to Postgre.

What must be happening is that you are trying to run the application with it in the air.

Stop tomcat and make sure the application is out (just go to link ).

Note: To stop tomcat just click on a red square that is located in the upper right corner of the Console tab.

Once this has been done, upload the project again, if you make a mistake about the bank, comment here again.

    
17.04.2018 / 16:48