Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring.database.username defaults to sa at all times #94

Closed
nebhale opened this issue Oct 17, 2013 · 3 comments
Closed

spring.database.username defaults to sa at all times #94

nebhale opened this issue Oct 17, 2013 · 3 comments

Comments

@nebhale
Copy link
Member

nebhale commented Oct 17, 2013

Currently the value of spring.database.username defaults to sa at all times. If you choose to use a different database that doesn't require a username (Postgres for example, can authenticate by process owner), there isn't a great way to indicate that you want to use no username.

The following fails with FATAL: rolde "sa" does not exist which stands to reason.

---
spring:
  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost/test

The following fails with FATAL: no PostgreSQL username specified in startup packet which again matches expectations because it's not that the username is empty, it's that it shouldn't be set at all.

---
spring:
  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost/test
    username:

A workaround at the moment is to use the $USER or user.name.

---
spring:
  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost/test
    username: ${user.name}

This work around isn't ideal and I think that boot shouldn't use the sa default if it hasn't also defaulted the url. Arguably, the defaulting of org.h2.Driver shouldn't happen for the same reasons.

@dsyer
Copy link
Member

dsyer commented Oct 23, 2013

Does this work?

spring:
  datasource:
    username: null

@nebhale
Copy link
Member Author

nebhale commented Oct 24, 2013

I've not tried it. I'll try and give it a go today.

@nebhale
Copy link
Member Author

nebhale commented Oct 24, 2013

No it does not:

org.postgresql.util.PSQLException: FATAL: no PostgreSQL user name specified in startup packet

It would appear that setting it to null is different than not setting it.

@dsyer dsyer closed this as completed in 97e6d77 Nov 4, 2013
gigfork pushed a commit to boostrack/spring-boot that referenced this issue Apr 21, 2014
To use a DataSource pool (Tomcat or DBCP) the user must supply a valid
driver class name *and* database URL. If both are supplied and the
driver class is not one of the embedded ones, then no default username
or password is provided.

Fixes spring-projectsgh-94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants