spring-in-action-5-samples icon indicating copy to clipboard operation
spring-in-action-5-samples copied to clipboard

Need to add application.properties file

Open aCodeRancher opened this issue 6 years ago • 11 comments

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

aCodeRancher avatar Sep 23 '18 20:09 aCodeRancher

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?

habuma avatar Sep 25 '18 05:09 habuma

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.

aCodeRancher avatar Sep 25 '18 16:09 aCodeRancher

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.

habuma avatar Dec 15 '18 00:12 habuma

@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 avatar Sep 05 '19 20:09 invzbl3

@invzbl3 From the 3rd Chapter, I can login to localhost:8080/design now.

aCodeRancher avatar Sep 07 '19 01:09 aCodeRancher

@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 avatar Sep 08 '19 09:09 invzbl3

@invzbl3 Yes. It works for me now.

aCodeRancher avatar Sep 08 '19 21:09 aCodeRancher

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 avatar Aug 01 '20 23:08 dassio

@dassio, Do you specify these in the application.properties: spring.h2.console.enabled=true spring.datasource.url=jdbc:h2:mem:testdb ?

aCodeRancher avatar Aug 02 '20 00:08 aCodeRancher

no, but after adding it, i can use jdbc:h2:mem:testdb

dassio avatar Aug 02 '20 08:08 dassio

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!

ChloeZPan avatar Aug 03 '21 09:08 ChloeZPan