spring-in-action-5-samples
spring-in-action-5-samples copied to clipboard
Need to add application.properties file
The application.yml should be renamed into application.properties. It should have this content:
spring.h2.console.enabled=true spring.h2.console.path=/h2
#Datasource can points to any file name, in this case, we call it test. spring.datasource.url=jdbc:h2:file:~/test spring.datasource.username=sa spring.datasource.password= spring.datasource.driver-class-name=org.h2.Driver
I generally prefer application.yml over application.properties. But can you (1) point out which application.yml you are referring to and (2) explain why you think it should be a properties file instead of a YAML file?
Hi, habuma, I am talking out the application.yml in ch03/tacos-jdbc . Without those configurations in application.properties, I cannot access to the h2 database via localhost:8080/h2.
Ah, so you are using a standalone H2 database, rather than an embedded one. In that case, yes, you would need to set those properties. For the purposes of these examples, I'm using an embedded H2 databased. I sorta show how to do this in section 5.1.2, but with an external MySQL database. Same idea, just different database type.
@aCodeRancher, did you open correct login page from 3rd chapter? Because I added this properties file, web link is working, but JDBC URL is not like in book.
@invzbl3 From the 3rd Chapter, I can login to localhost:8080/design now.
@aCodeRancher I mean, if you open localhost:8080/h2-console
, is your JDBC url exactly the same as in the book from example jdbc:h2:mem:testdb
or by default jdbc:h2:~/test
? In my case, I need to change manually jdbc:h2:~/test
to jdbc:h2:mem:testdb
after running the page first time, because I don't understand how to edit it programmatically using this answer.
@invzbl3 Yes. It works for me now.
there is an output of the spring command line:
2020-08-02 00:28:35.783 INFO 685411 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:bef84abd-c17a-40a9-89a4-75ff418266df'
by using jdbc:h2:mem:bef84abd-c17a-40a9-89a4-75ff418266df for the JDBC url works for me , the jdbc:h2:mem:testdb does not work .
@dassio, Do you specify these in the application.properties: spring.h2.console.enabled=true spring.datasource.url=jdbc:h2:mem:testdb ?
no, but after adding it, i can use jdbc:h2:mem:testdb
Is it possible to access the embedded h2 console after finishing all the coding in chapter 1 via localhost:8080/h2-console? in the book, on page 25, it says it could but I got a 404 error. Thank you!