java - What is the Best Approach to connect to database in Spring4 and Tomcat application? -


we working on web application using spring4 , tomcat7.i doing database set part first time not sure put database confiuration part (datasource creation) in spring context.xml or in tomcat context.xml advantages of both these approaches , better approach? also,our application communicating 1 database.

please me out.

presuming of course new application, recommend spring boot, spring data jpa. here link tutorial spring data rest. think if insist on manually wiring entity manager , datasource, you'd best off doing in javaconfig. spring boot can configure database you have provide connection string in application.properties. so.

spring.datasource.url=jdbc:mysql://localhost/test spring.datasource.username=dbuser spring.datasource.password=dbpass spring.datasource.driver-class-name=com.mysql.jdbc.driver 

important do not commit production database credentials source code. it's fine localhost developer credentials. spring boot has facilities allow avoid this.

although not recommend xml approach far more complicated spring boot alternatives , lacks type safety of java config.

you choose tomcat configuration if planning on running more 1 application in tomcat instance needed use same datasource. argued older reason choosing have different credentials different servers, or keep credentials out of source, modern spring has several solutions built in this.

you choose spring configuration if wanted able move different web server, such jetty or undertow.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -