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

a year 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

a year ago

Are you using springboot data jpa or mybatis


eldadjacobi1
HOBBYOP

a year ago

9cf784b6-e7ca-4460-8143-8d0332e36770


eldadjacobi1
HOBBYOP

a year ago

springboot


eldadjacobi1
HOBBYOP

a year ago

datasource:

url: ${DATABASE_URL}

username: ${DB_USERNAME}

password: ${DB_PASSWORD}

driver-class-name: org.postgresql.Driver

jpa:

show-sql: true

properties:

hibernate:

format_sql: true

hibernate:

ddl-auto: update


a year ago

I believe you're missing the spring key before datasource


a year ago

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

eldadjacobi1
HOBBYOP

a year 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: ${DATABASE_URL}

username: ${DB_USERNAME}

password: ${DB_PASSWORD}

driver-class-name: org.postgresql.Driver

jpa:

show-sql: true

properties:

hibernate:

format_sql: true

hibernate:

ddl-auto: update


a year ago

please use code blocks


eldadjacobi1
HOBBYOP

a year ago

how


a year ago

You're setting the DATABASE_URL environmental variable?


a year ago

```

before and after


eldadjacobi1
HOBBYOP

a year ago

I see this in the connect tab


eldadjacobi1
HOBBYOP

a year ago

1387262280743387197


a year 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}}



a year ago

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


eldadjacobi1
HOBBYOP

a year ago

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


a year ago

No idea what that means


a year ago

Ah sorry that's not going to work because JDBC


a year ago

Brb


a year ago

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

That should do the job


eldadjacobi1
HOBBYOP

a year ago

where do I put this


a year ago

DATABASE_URL value


a year ago

Replace what you have for it


a year ago

Java is stupid


eldadjacobi1
HOBBYOP

a year ago

what about the DB_USERNAME and DB_PASSWORD


a year ago

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

eldadjacobi1
HOBBYOP

a year ago

let me try that now


eldadjacobi1
HOBBYOP

a year ago

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

or just: ${{Postgres.RAILWAY_PRIVATE_DOMAIN}}


a year ago

the first one


a year ago

the whole thing


a year ago

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


eldadjacobi1
HOBBYOP

a year ago

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


eldadjacobi1
HOBBYOP

a year ago

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


a year ago

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


a year ago

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


eldadjacobi1
HOBBYOP

a year ago

mmm good question


eldadjacobi1
HOBBYOP

a year ago

where do I check


a year ago

Screenshot your architecture page


eldadjacobi1
HOBBYOP

a year ago

these one?

1387268218032361552

1387268218481283082

1387268218845921410

1387268219223543878


a year ago

Oh nos you have to have them in the same project


a year ago

Won't work unless you do


a year ago

Why do you have them in different projects?


eldadjacobi1
HOBBYOP

a year ago

I am not sure, let me try move it


eldadjacobi1
HOBBYOP

a year ago

or maybe I need to create a new one


a year ago

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


a year ago

But once you do it should immediately all work


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


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


a year ago

they aren't doing that anyway


eldadjacobi1
HOBBYOP

a year ago

do I use public URL now? 😦


a year ago

no...


eldadjacobi1
HOBBYOP

a year ago

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"```


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


Then use internal variables


a year ago

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


a year ago

(and make sure it's still called Postgres)


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


eldadjacobi1
HOBBYOP

a year ago

this project:

1387269638898847865


a year ago

perfect


eldadjacobi1
HOBBYOP

a year ago

crashed 😦


a year ago

what's the error this time


eldadjacobi1
HOBBYOP

a year ago

checking


yeah share the error logs


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


a year ago

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


eldadjacobi1
HOBBYOP

a year 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


a year ago

That's just an error with your application


a year ago

Are you sure there isn't more to that


a year ago

Do you need to provide an open ai key perhaps


eldadjacobi1
HOBBYOP

a year ago

I tought I did, let me check


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


a year ago

That error is going to crash the whole thing


a year ago

Not sure why it says warning


Agree


eldadjacobi1
HOBBYOP

a year ago

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


a year ago

yerp


eldadjacobi1
HOBBYOP

a year ago

what is the best way to see love logs?


a year ago

click the service, the deploymeny, and then logs?


eldadjacobi1
HOBBYOP

a year ago

yes but now I send a postman request and get 502


eldadjacobi1
HOBBYOP

a year ago

and don't see anyting in logs


a year ago

What port did you give the domain


a year ago

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


eldadjacobi1
HOBBYOP

a year ago

I jave variable PORT:8080


eldadjacobi1
HOBBYOP

a year ago

maybe I am not using the right hostname


a year ago

= or colon


a year ago

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


a year ago

And does Springboot show it bound to 8080 in deployment logs


eldadjacobi1
HOBBYOP

a year ago

the last thing that I see in logs is:


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)```


a year ago

Screenshot your public domain part of settings


eldadjacobi1
HOBBYOP

a year ago

wait I found the domain


eldadjacobi1
HOBBYOP

a year ago

it's: layers-production.up.railway.app


eldadjacobi1
HOBBYOP

a year ago

now it's working!!!


eldadjacobi1
HOBBYOP

a year ago

yay


a year ago

great!


eldadjacobi1
HOBBYOP

a year ago

I mean I get some error but it is expected...


eldadjacobi1
HOBBYOP

a year ago

now I have to deal with my own app


eldadjacobi1
HOBBYOP

a year ago

but at least it is working


eldadjacobi1
HOBBYOP

a year ago

thank you so much!!!!!!


eldadjacobi1
HOBBYOP

a year ago

I'm so happy


eldadjacobi1
HOBBYOP

a year ago

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


a year ago

from Java...?


eldadjacobi1
HOBBYOP

a year ago

no, in the railway postgres itself


eldadjacobi1
HOBBYOP

a year ago

I can see the tables


a year ago

you'll need to use the Railway CLI


a year ago

then use railway connect


eldadjacobi1
HOBBYOP

a year ago

ok I will read about it


jesushdez
HOBBY

a year 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 about 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...