unable to connect to postgres, no url but there is clearly a url variable
eldadjacobi1
HOBBYOP

7 months ago

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
but there is a var for url 100%

Solved$10 Bounty

108 Replies

samgordon
PRO

7 months ago

Are you using springboot data jpa or mybatis


eldadjacobi1
HOBBYOP

7 months ago

9cf784b6-e7ca-4460-8143-8d0332e36770


eldadjacobi1
HOBBYOP

7 months ago

springboot


eldadjacobi1
HOBBYOP

7 months ago

datasource:
url: ${DATABASEURL} username: ${DBUSERNAME}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver

jpa:
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: update


samgordon
PRO

7 months ago

I believe you're missing the spring key before datasource


samgordon
PRO

7 months ago

spring:
    datasource:
        url: ${DATABASE_URL}
        username: ${DB_USERNAME}
        password: ${DB_PASSWORD}
        driver-class-name: org.postgresql.Driver

eldadjacobi1
HOBBYOP

7 months ago

I have it, it is working on local, it also worked before on railway until I started a new application, I forgot what I used in the variables

spring:
application:
name: Layers

datasource:
url: ${DATABASEURL} username: ${DBUSERNAME}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver

jpa:
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: update


samgordon
PRO

7 months ago

please use code blocks


eldadjacobi1
HOBBYOP

7 months ago

how


samgordon
PRO

7 months ago

You're setting the DATABASE_URL environmental variable?


samgordon
PRO

7 months ago

```

before and after


eldadjacobi1
HOBBYOP

7 months ago

I see this in the connect tab


eldadjacobi1
HOBBYOP

7 months ago

1387262280743387100


samgordon
PRO

7 months ago

What you need to do is make an environmental variable in your Springboot app called DATABASE_URL

Assign it to the value ${{Postgres.DATABASE_URL}}



samgordon
PRO

7 months ago

That's your raw variables in your Springboot service, correct?


eldadjacobi1
HOBBYOP

7 months ago

so the URL is from the private tab and the username and password are from the public tab


samgordon
PRO

7 months ago

No idea what that means


samgordon
PRO

7 months ago

Ah sorry that's not going to work because JDBC


samgordon
PRO

7 months ago

Brb


samgordon
PRO

7 months ago

jdbc:postgresql://${{Postgres.RAILWAY_PRIVATE_DOMAIN}}:${{Postgres.PGPORT}}/${{Postgres.PGDATABASE}}

That should do the job


eldadjacobi1
HOBBYOP

7 months ago

where do I put this


samgordon
PRO

7 months ago

DATABASE_URL value


samgordon
PRO

7 months ago

Replace what you have for it


samgordon
PRO

7 months ago

Java is stupid


eldadjacobi1
HOBBYOP

7 months ago

what about the DBUSERNAME and DBPASSWORD


samgordon
PRO

7 months ago

DB_PASSWORD="${{Postgres.PGPASSWORD}}"
DB_USERNAME="${{Postgres.PGUSER}}"

eldadjacobi1
HOBBYOP

7 months ago

let me try that now


eldadjacobi1
HOBBYOP

7 months ago

so in URL do I put: jdbc:postgresql://${{Postgres.RAILWAYPRIVATEDOMAIN}}:${{Postgres.PGPORT}}/${{Postgres.PGDATABASE}}

or just: ${{Postgres.RAILWAYPRIVATEDOMAIN}}


samgordon
PRO

7 months ago

the first one


samgordon
PRO

7 months ago

the whole thing


samgordon
PRO

7 months ago

DATABASE_URL=jdbc:postgresql://${{Postgres.RAILWAY_PRIVATE_DOMAIN}}:${{Postgres.PGPORT}}/${{Postgres.PGDATABASE}}


eldadjacobi1
HOBBYOP

7 months ago

java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, jdbc:postgresql://:/


eldadjacobi1
HOBBYOP

7 months ago

I think there are extra quotation, I'll remove and try again


samgordon
PRO

7 months ago

Yeah that error shows that none of the env variables actually resolved


samgordon
PRO

7 months ago

Your Postgres service is still called what it was up there right


eldadjacobi1
HOBBYOP

7 months ago

mmm good question


eldadjacobi1
HOBBYOP

7 months ago

where do I check


samgordon
PRO

7 months ago

Screenshot your architecture page


eldadjacobi1
HOBBYOP

7 months ago

these one?

1387268218032361500
1387268218481283000
1387268218845921500
1387268219223543800


samgordon
PRO

7 months ago

Oh nos you have to have them in the same project


samgordon
PRO

7 months ago

Won't work unless you do


samgordon
PRO

7 months ago

Why do you have them in different projects?


eldadjacobi1
HOBBYOP

7 months ago

I am not sure, let me try move it


eldadjacobi1
HOBBYOP

7 months ago

or maybe I need to create a new one


samgordon
PRO

7 months ago

You can't move it you'll need to make a new one


samgordon
PRO

7 months ago

But once you do it should immediately all work


warengonzaga
PRO

7 months ago

Looks like they are all in different projects; it should be in one project.


warengonzaga
PRO

7 months ago

If you connect them using public URL it will cost you egress so it is efficient in one project and use internal URL.


samgordon
PRO

7 months ago

they aren't doing that anyway


eldadjacobi1
HOBBYOP

7 months ago

do I use public URL now? 😦


samgordon
PRO

7 months ago

no…


eldadjacobi1
HOBBYOP

7 months ago

DATABASE_URL="jdbc:postgresql://${{Postgres.RAILWAY_PRIVATE_DOMAIN}}:${{Postgres.PGPORT}}/${{Postgres.PGDATABASE}}" DB_PASSWORD="${{Postgres.PGPASSWORD}}" DB_USERNAME="${{Postgres.PGUSER}}" EMAIL_PASSWORD="okfaezxundjhutyf" EMAIL_USERNAME="layers.app1@gmail.com" JWT_SECRET="MyVeryStrongJWTSecretKey_987654321!@" NIXPACKS_JDK_VERSION="21" PORT="8080"


warengonzaga
PRO

7 months ago

It will work, but in your case you should use one project.


warengonzaga
PRO

7 months ago

Then use internal variables


samgordon
PRO

7 months ago

As long as you moved your database over to that project you're golden


samgordon
PRO

7 months ago

(and make sure it's still called Postgres)


warengonzaga
PRO

7 months ago

Yeah the solution here, just move them in your project then it should work.


eldadjacobi1
HOBBYOP

7 months ago

this project:

1387269638898847700


samgordon
PRO

7 months ago

perfect


eldadjacobi1
HOBBYOP

7 months ago

crashed 😦


samgordon
PRO

7 months ago

what's the error this time


eldadjacobi1
HOBBYOP

7 months ago

checking


warengonzaga
PRO

7 months ago

yeah share the error logs


warengonzaga
PRO

7 months ago

@Loudbook I think the user should delete this? It has secrets and email passwords.


samgordon
PRO

7 months ago

considering it says "MyVeryStrong…" i would assume they're going to change it


eldadjacobi1
HOBBYOP

7 months ago

2025-06-25T03:15:04.790Z WARN 1 --- [Layers] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openAIClient': Injection of autowired dependencies failed


samgordon
PRO

7 months ago

That's just an error with your application


samgordon
PRO

7 months ago

Are you sure there isn't more to that


samgordon
PRO

7 months ago

Do you need to provide an open ai key perhaps


eldadjacobi1
HOBBYOP

7 months ago

I tought I did, let me check


warengonzaga
PRO

7 months ago

Looks like warning only, it would help if you share the actual error that causes to crash.


samgordon
PRO

7 months ago

That error is going to crash the whole thing


samgordon
PRO

7 months ago

Not sure why it says warning


warengonzaga
PRO

7 months ago

Agree


eldadjacobi1
HOBBYOP

7 months ago

I was missing that API_KEY I added it now and I am restarting


samgordon
PRO

7 months ago

yerp


eldadjacobi1
HOBBYOP

7 months ago

what is the best way to see love logs?


samgordon
PRO

7 months ago

click the service, the deploymeny, and then logs?


eldadjacobi1
HOBBYOP

7 months ago

yes but now I send a postman request and get 502


eldadjacobi1
HOBBYOP

7 months ago

and don't see anyting in logs


samgordon
PRO

7 months ago

What port did you give the domain


samgordon
PRO

7 months ago

Set PORT=8080, redeploy your service, and delete the public domain and re-add it


eldadjacobi1
HOBBYOP

7 months ago

I jave variable PORT:8080


eldadjacobi1
HOBBYOP

7 months ago

maybe I am not using the right hostname


samgordon
PRO

7 months ago

= or colon


samgordon
PRO

7 months ago

Does your public domain in the server settings show it's pointing to it


samgordon
PRO

7 months ago

And does Springboot show it bound to 8080 in deployment logs


eldadjacobi1
HOBBYOP

7 months ago

the last thing that I see in logs is:

```2025-06-25T03:21:54.511Z DEBUG 1 --- [Layers] [ main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 1 @ExceptionHandler, 0 ResponseBodyAdvice

2025-06-25T03:21:54.723Z INFO 1 --- [Layers] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'

2025-06-25T03:21:54.732Z INFO 1 --- [Layers] [ main] c.e.ai.chateldadt.ChatEldadTApplication : Started ChatEldadTApplication in 6.564 seconds (process running for 7.117)```


samgordon
PRO

7 months ago

Screenshot your public domain part of settings


eldadjacobi1
HOBBYOP

7 months ago

wait I found the domain


eldadjacobi1
HOBBYOP

7 months ago


eldadjacobi1
HOBBYOP

7 months ago

now it's working!!!


eldadjacobi1
HOBBYOP

7 months ago

yay


samgordon
PRO

7 months ago

great!


eldadjacobi1
HOBBYOP

7 months ago

I mean I get some error but it is expected…


eldadjacobi1
HOBBYOP

7 months ago

now I have to deal with my own app


eldadjacobi1
HOBBYOP

7 months ago

but at least it is working


eldadjacobi1
HOBBYOP

7 months ago

thank you so much!!!!!!


eldadjacobi1
HOBBYOP

7 months ago

I'm so happy


eldadjacobi1
HOBBYOP

7 months ago

can I ask how do I write an SQL query in postgres?


samgordon
PRO

7 months ago

from Java…?


eldadjacobi1
HOBBYOP

7 months ago

no, in the railway postgres itself


eldadjacobi1
HOBBYOP

7 months ago

I can see the tables


samgordon
PRO

7 months ago

you'll need to use the Railway CLI


samgordon
PRO

7 months ago

then use railway connect


eldadjacobi1
HOBBYOP

7 months ago

ok I will read about it


root101
HOBBY

7 months ago

You can also use a custom tool like pgadmin

Note that you will need to connect to the DB through it's public URL


Status changed to Solved chandrika 8 months ago


Loading...