diff --git a/generators/server/index.js b/generators/server/index.js index 03c72351..b64ae991 100644 --- a/generators/server/index.js +++ b/generators/server/index.js @@ -195,11 +195,8 @@ module.exports = class extends BaseGenerator { ]; this.generateMainJavaCode(configOptions, mainJavaTemplates); - const mainResTemplates = [ - 'application.properties', - 'application-local.properties', - 'logback-spring.xml' - ]; + const mainResTemplates = this._getResourceFileTemplates(configOptions) + this.generateMainResCode(configOptions, mainResTemplates); const testJavaTemplates = [ @@ -214,13 +211,35 @@ module.exports = class extends BaseGenerator { } this.generateTestJavaCode(configOptions, testJavaTemplates); - const testResTemplates = [ - 'application-test.properties', - 'logback-test.xml' - ]; + const testResTemplates = this._getResourceFileTestTemplates(configOptions) + this.generateTestResCode(configOptions, testResTemplates); } + _getResourceFileTestTemplates(configOptions) { + let testResYamlTemplates = [] + + if (configOptions.propFileFormat === 'yaml') { + testResYamlTemplates = ['application-test.yml'] + } + else { + testResYamlTemplates = ['application-test.properties'] + } + return [...testResYamlTemplates, 'logback-test.xml'] + } + + _getResourceFileTemplates(configOptions) { + let mainResTemplates = [] + + if (configOptions.propFileFormat === 'yaml') { + mainResTemplates = ['application.yml', 'application-local.yml'] + } else { + mainResTemplates = ['application.properties', 'application-local.properties'] + } + + return [...mainResTemplates, 'logback-spring.xml'] + } + _generateDbMigrationConfig(configOptions) { if(configOptions.dbMigrationTool === 'flywaydb') { let vendor = configOptions.databaseType; diff --git a/generators/server/prompts.js b/generators/server/prompts.js index 3521639d..6e3bba98 100644 --- a/generators/server/prompts.js +++ b/generators/server/prompts.js @@ -123,6 +123,21 @@ function prompting() { } ], default: 'maven' + }, + { + type: 'list', + name: 'propFileFormat', + message: 'which format do you want to use for configuration files?', + choices: [ + { + value: 'props', + name: 'Property File' + }, + { + value: 'yaml', + name: 'YAML' + } + ] } ]; diff --git a/generators/server/templates/app/src/main/resources/application-local.yml b/generators/server/templates/app/src/main/resources/application-local.yml new file mode 100644 index 00000000..3d0c1971 --- /dev/null +++ b/generators/server/templates/app/src/main/resources/application-local.yml @@ -0,0 +1,31 @@ +<%_ if (databaseType === 'postgresql') { _%> +spring: + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://localhost:5432/appdb +<%_ } _%> +<%_ if (databaseType === 'mysql') { _%> + datasource: + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://localhost:3306/appdb +<%_ } _%> +<%_ if (databaseType === 'mariadb') { _%> + datasource: + driver-class-name: org.mariadb.jdbc.Driver + url: jdbc:mariadb://localhost:3306/appdb +<%_ } _%> + datasource: + username: appuser + password: secret + +<%_ if (features.includes('localstack')) { _%> +###AWS + cloud: + aws: + region: + static: us-east-1 + credentials: + secret-key: noop + access-key: noop + endpoint: http://localhost:4566 +<%_ } _%> diff --git a/generators/server/templates/app/src/main/resources/application.yml b/generators/server/templates/app/src/main/resources/application.yml new file mode 100644 index 00000000..6668a527 --- /dev/null +++ b/generators/server/templates/app/src/main/resources/application.yml @@ -0,0 +1,66 @@ +spring: + application: + name: <%= appName %> + main: + allow-bean-definition-overriding: 'true' + jmx: + enabled: 'false' + mvc: + problemdetails: + enabled: 'true' +server: + port: '8080' + shutdown: graceful + +################ Actuator ##################### +management: + endpoints: + web: + exposure: + include: configprops,env,health,info,logfile,loggers,metrics,prometheus + endpoint: + health: + show-details: always + +################### Database ################### +spring: + jpa: + open-in-view: 'false' + show-sql: 'false' + hibernate: + ddl-auto: none + properties: + hibernate: + jdbc: + time_zone: UTC + batch_size: '25' + lob: + non_contextual_creation: 'true' + query: + fail_on_pagination_over_collection_fetch: 'true' + plan_cache_max_size: '4096' + in_clause_parameter_padding: 'true' + generate_statistics: 'false' + order_inserts: 'true' + connection: + provider_disables_autocommit: 'true' + order_updates: 'true' + datasource: + hikari: + data-source-properties: + ApplicationName: ${spring.application.name} + auto-commit: 'false' + data: + jpa: + repositories: + bootstrap-mode: deferred + +<%_ if (dbMigrationTool === 'flywaydb') { _%> + flyway: + locations: classpath:/db/migration/{vendor} +<%_ } _%> + +<%_ if (features.includes('elk')) { _%> +application: + logstash-host: localhost +<%_ } _%> diff --git a/generators/server/templates/app/src/test/resources/application-test.yml b/generators/server/templates/app/src/test/resources/application-test.yml new file mode 100644 index 00000000..c7dd4e02 --- /dev/null +++ b/generators/server/templates/app/src/test/resources/application-test.yml @@ -0,0 +1,11 @@ +<%_ if (features.includes('localstack')) { _%> +spring: + cloud: + aws: + region: + static: us-east-1 + credentials: + secret-key: noop + access-key: noop + endpoint: http://localhost:4566 +<%_ } _%>