BAEL-521 (#1799)
* refactor: Moved JHipster Monolithic to a subfolder * feat: Add JHipster Microservice modules closes BAEL-521
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
######################
|
||||
# Project Specific
|
||||
######################
|
||||
/target/www/**
|
||||
/src/test/javascript/coverage/
|
||||
/src/test/javascript/PhantomJS*/
|
||||
|
||||
######################
|
||||
# Node
|
||||
######################
|
||||
/node/
|
||||
node_tmp/
|
||||
node_modules/
|
||||
npm-debug.log.*
|
||||
|
||||
######################
|
||||
# SASS
|
||||
######################
|
||||
.sass-cache/
|
||||
|
||||
######################
|
||||
# Eclipse
|
||||
######################
|
||||
*.pydevproject
|
||||
.project
|
||||
.metadata
|
||||
tmp/
|
||||
tmp/**/*
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.classpath
|
||||
.settings/
|
||||
.loadpath
|
||||
.factorypath
|
||||
/src/main/resources/rebel.xml
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/**
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
######################
|
||||
# Intellij
|
||||
######################
|
||||
.idea/
|
||||
*.iml
|
||||
*.iws
|
||||
*.ipr
|
||||
*.ids
|
||||
*.orig
|
||||
|
||||
######################
|
||||
# Visual Studio Code
|
||||
######################
|
||||
.vscode/
|
||||
|
||||
######################
|
||||
# Maven
|
||||
######################
|
||||
/log/
|
||||
/target/
|
||||
|
||||
######################
|
||||
# Gradle
|
||||
######################
|
||||
.gradle/
|
||||
/build/
|
||||
|
||||
######################
|
||||
# Package Files
|
||||
######################
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.db
|
||||
|
||||
######################
|
||||
# Windows
|
||||
######################
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
######################
|
||||
# Mac OSX
|
||||
######################
|
||||
.DS_Store
|
||||
.svn
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear on external disk
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
######################
|
||||
# Directories
|
||||
######################
|
||||
/bin/
|
||||
/deploy/
|
||||
|
||||
######################
|
||||
# Logs
|
||||
######################
|
||||
*.log
|
||||
|
||||
######################
|
||||
# Others
|
||||
######################
|
||||
*.class
|
||||
*.*~
|
||||
*~
|
||||
.merge_file*
|
||||
|
||||
######################
|
||||
# Gradle Wrapper
|
||||
######################
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
######################
|
||||
# Maven Wrapper
|
||||
######################
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
######################
|
||||
# ESLint
|
||||
######################
|
||||
.eslintcache
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"fluentMethods": true,
|
||||
"relationships": [],
|
||||
"fields": [
|
||||
{
|
||||
"fieldName": "make",
|
||||
"fieldType": "String"
|
||||
},
|
||||
{
|
||||
"fieldName": "brand",
|
||||
"fieldType": "String"
|
||||
},
|
||||
{
|
||||
"fieldName": "price",
|
||||
"fieldType": "Double"
|
||||
}
|
||||
],
|
||||
"changelogDate": "20170503041524",
|
||||
"dto": "no",
|
||||
"service": "no",
|
||||
"entityTableName": "car",
|
||||
"pagination": "infinite-scroll",
|
||||
"microserviceName": "carapp",
|
||||
"searchEngine": false
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"generator-jhipster": {
|
||||
"jhipsterVersion": "4.0.8",
|
||||
"baseName": "carapp",
|
||||
"packageName": "com.car.app",
|
||||
"packageFolder": "com/car/app",
|
||||
"serverPort": "8081",
|
||||
"authenticationType": "jwt",
|
||||
"hibernateCache": "hazelcast",
|
||||
"clusteredHttpSession": false,
|
||||
"websocket": false,
|
||||
"databaseType": "sql",
|
||||
"devDatabaseType": "h2Disk",
|
||||
"prodDatabaseType": "mysql",
|
||||
"searchEngine": false,
|
||||
"messageBroker": false,
|
||||
"serviceDiscoveryType": "eureka",
|
||||
"buildTool": "maven",
|
||||
"enableSocialSignIn": false,
|
||||
"jwtSecretKey": "0ebd193e0552c4ac548217d353abbde0761a1997",
|
||||
"enableTranslation": false,
|
||||
"applicationType": "microservice",
|
||||
"testFrameworks": [],
|
||||
"jhiPrefix": "jhi",
|
||||
"skipClient": true,
|
||||
"skipUserManagement": true,
|
||||
"clientPackageManager": "yarn"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
# carapp
|
||||
This application was generated using JHipster 4.0.8, you can find documentation and help at [https://jhipster.github.io/documentation-archive/v4.0.8](https://jhipster.github.io/documentation-archive/v4.0.8).
|
||||
|
||||
This is a "microservice" application intended to be part of a microservice architecture, please refer to the [Doing microservices with JHipster][] page of the documentation for more information.
|
||||
|
||||
This application is configured for Service Discovery and Configuration with the JHipster-Registry. On launch, it will refuse to start if it is not able to connect to the JHipster-Registry at [http://localhost:8761](http://localhost:8761). For more information, read our documentation on [Service Discovery and Configuration with the JHipster-Registry][].
|
||||
|
||||
## Development
|
||||
|
||||
To start your application in the dev profile, simply run:
|
||||
|
||||
./mvnw
|
||||
|
||||
|
||||
For further instructions on how to develop with JHipster, have a look at [Using JHipster in development][].
|
||||
|
||||
|
||||
## Building for production
|
||||
|
||||
To optimize the carapp application for production, run:
|
||||
|
||||
./mvnw -Pprod clean package
|
||||
|
||||
To ensure everything worked, run:
|
||||
|
||||
java -jar target/*.war
|
||||
|
||||
|
||||
Refer to [Using JHipster in production][] for more details.
|
||||
|
||||
## Testing
|
||||
|
||||
To launch your application's tests, run:
|
||||
|
||||
./mvnw clean test
|
||||
|
||||
For more information, refer to the [Running tests page][].
|
||||
|
||||
## Using Docker to simplify development (optional)
|
||||
|
||||
You can use Docker to improve your JHipster development experience. A number of docker-compose configuration are available in the [src/main/docker](src/main/docker) folder to launch required third party services.
|
||||
For example, to start a mysql database in a docker container, run:
|
||||
|
||||
docker-compose -f src/main/docker/mysql.yml up -d
|
||||
|
||||
To stop it and remove the container, run:
|
||||
|
||||
docker-compose -f src/main/docker/mysql.yml down
|
||||
|
||||
You can also fully dockerize your application and all the services that it depends on.
|
||||
To achieve this, first build a docker image of your app by running:
|
||||
|
||||
./mvnw package -Pprod docker:build
|
||||
|
||||
Then run:
|
||||
|
||||
docker-compose -f src/main/docker/app.yml up -d
|
||||
|
||||
For more information refer to [Using Docker and Docker-Compose][], this page also contains information on the docker-compose sub-generator (`yo jhipster:docker-compose`), which is able to generate docker configurations for one or several JHipster applications.
|
||||
|
||||
## Continuous Integration (optional)
|
||||
|
||||
To configure CI for your project, run the ci-cd sub-generator (`yo jhipster:ci-cd`), this will let you generate configuration files for a number of Continuous Integration systems. Consult the [Setting up Continuous Integration][] page for more information.
|
||||
|
||||
[JHipster Homepage and latest documentation]: https://jhipster.github.io
|
||||
[JHipster 4.0.8 archive]: https://jhipster.github.io/documentation-archive/v4.0.8
|
||||
[Doing microservices with JHipster]: https://jhipster.github.io/documentation-archive/v4.0.8/microservices-architecture/
|
||||
[Using JHipster in development]: https://jhipster.github.io/documentation-archive/v4.0.8/development/
|
||||
[Service Discovery and Configuration with the JHipster-Registry]: https://jhipster.github.io/documentation-archive/v4.0.8/microservices-architecture/#jhipster-registry
|
||||
[Using Docker and Docker-Compose]: https://jhipster.github.io/documentation-archive/v4.0.8/docker-compose
|
||||
[Using JHipster in production]: https://jhipster.github.io/documentation-archive/v4.0.8/production/
|
||||
[Running tests page]: https://jhipster.github.io/documentation-archive/v4.0.8/running-tests/
|
||||
[Setting up Continuous Integration]: https://jhipster.github.io/documentation-archive/v4.0.8/setting-up-ci/
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"generator-jhipster": "4.0.8"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
|
||||
JHIPSTER_SLEEP=0
|
||||
|
||||
# add directly the war
|
||||
ADD *.war /app.war
|
||||
|
||||
VOLUME /tmp
|
||||
EXPOSE 8081 5701/udp
|
||||
CMD echo "The application will start in ${JHIPSTER_SLEEP}s..." && \
|
||||
sleep ${JHIPSTER_SLEEP} && \
|
||||
java -Djava.security.egd=file:/dev/./urandom -jar /app.war
|
||||
@@ -0,0 +1,19 @@
|
||||
version: '2'
|
||||
services:
|
||||
carapp-app:
|
||||
image: carapp
|
||||
environment:
|
||||
- SPRING_PROFILES_ACTIVE=prod,swagger
|
||||
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/config
|
||||
- SPRING_DATASOURCE_URL=jdbc:mysql://carapp-mysql:3306/carapp?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
- JHIPSTER_SLEEP=10 # gives time for the database to boot before the application
|
||||
carapp-mysql:
|
||||
extends:
|
||||
file: mysql.yml
|
||||
service: carapp-mysql
|
||||
jhipster-registry:
|
||||
extends:
|
||||
file: jhipster-registry.yml
|
||||
service: jhipster-registry
|
||||
environment:
|
||||
- SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:./central-config/docker-config/
|
||||
@@ -0,0 +1,7 @@
|
||||
# Central configuration sources details
|
||||
|
||||
The JHipster-Registry will use the following directories as its configuration source :
|
||||
- localhost-config : when running the registry in docker with the jhipster-registry.yml docker-compose file
|
||||
- docker-config : when running the registry and the app both in docker with the app.yml docker-compose file
|
||||
|
||||
For more info, refer to http://jhipster.github.io/microservices-architecture/#registry_app_configuration
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Common configuration shared between all applications
|
||||
configserver:
|
||||
name: Docker JHipster Registry
|
||||
status: Connected to the JHipster Registry running in Docker
|
||||
|
||||
jhipster:
|
||||
security:
|
||||
authentication:
|
||||
jwt:
|
||||
secret: my-secret-token-to-change-in-production
|
||||
|
||||
eureka:
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://admin:${jhipster.registry.password}@jhipster-registry:8761/eureka/
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Common configuration shared between all applications
|
||||
configserver:
|
||||
name: Docker JHipster Registry
|
||||
status: Connected to the JHipster Registry running in Docker
|
||||
|
||||
jhipster:
|
||||
security:
|
||||
authentication:
|
||||
jwt:
|
||||
secret: my-secret-token-to-change-in-production
|
||||
|
||||
eureka:
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://admin:${jhipster.registry.password}@localhost:8761/eureka/
|
||||
@@ -0,0 +1,18 @@
|
||||
version: '2'
|
||||
services:
|
||||
jhipster-registry:
|
||||
image: jhipster/jhipster-registry:v2.5.8
|
||||
volumes:
|
||||
- ./central-server-config:/central-config
|
||||
# When run with the "dev" Spring profile, the JHipster Registry will
|
||||
# read the config from the local filesystem (central-server-config directory)
|
||||
# When run with the "prod" Spring profile, it will read the config from a git repository
|
||||
# See http://jhipster.github.io/microservices-architecture/#registry_app_configuration
|
||||
environment:
|
||||
- SPRING_PROFILES_ACTIVE=dev
|
||||
- SECURITY_USER_PASSWORD=admin
|
||||
- SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:./central-config/localhost-config/
|
||||
# - GIT_URI=https://github.com/jhipster/jhipster-registry/
|
||||
# - GIT_SEARCH_PATHS=central-config
|
||||
ports:
|
||||
- 8761:8761
|
||||
@@ -0,0 +1,13 @@
|
||||
version: '2'
|
||||
services:
|
||||
carapp-mysql:
|
||||
image: mysql:5.7.13
|
||||
# volumes:
|
||||
# - ~/volumes/jhipster/carapp/mysql/:/var/lib/mysql/
|
||||
environment:
|
||||
- MYSQL_USER=root
|
||||
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
|
||||
- MYSQL_DATABASE=carapp
|
||||
ports:
|
||||
- 3306:3306
|
||||
command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8
|
||||
@@ -0,0 +1,7 @@
|
||||
version: '2'
|
||||
services:
|
||||
carapp-sonar:
|
||||
image: sonarqube:6.2-alpine
|
||||
ports:
|
||||
- 9000:9000
|
||||
- 9092:9092
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.car.app;
|
||||
|
||||
import com.car.app.config.DefaultProfileUtil;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
|
||||
/**
|
||||
* This is a helper Java class that provides an alternative to creating a web.xml.
|
||||
* This will be invoked only when the application is deployed to a servlet container like Tomcat, JBoss etc.
|
||||
*/
|
||||
public class ApplicationWebXml extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
/**
|
||||
* set a default to use when no profile is configured.
|
||||
*/
|
||||
DefaultProfileUtil.addDefaultProfile(application.application());
|
||||
return application.sources(CarappApp.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.car.app;
|
||||
|
||||
import com.car.app.config.ApplicationProperties;
|
||||
import com.car.app.config.DefaultProfileUtil;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.autoconfigure.*;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
|
||||
@EnableConfigurationProperties({LiquibaseProperties.class, ApplicationProperties.class})
|
||||
@EnableDiscoveryClient
|
||||
public class CarappApp {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CarappApp.class);
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public CarappApp(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes carapp.
|
||||
* <p>
|
||||
* Spring profiles can be configured with a program arguments --spring.profiles.active=your-active-profile
|
||||
* <p>
|
||||
* You can find more information on how profiles work with JHipster on <a href="http://jhipster.github.io/profiles/">http://jhipster.github.io/profiles/</a>.
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initApplication() {
|
||||
Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
|
||||
if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT) && activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) {
|
||||
log.error("You have misconfigured your application! It should not run " +
|
||||
"with both the 'dev' and 'prod' profiles at the same time.");
|
||||
}
|
||||
if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT) && activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_CLOUD)) {
|
||||
log.error("You have misconfigured your application! It should not" +
|
||||
"run with both the 'dev' and 'cloud' profiles at the same time.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method, used to run the application.
|
||||
*
|
||||
* @param args the command line arguments
|
||||
* @throws UnknownHostException if the local host name could not be resolved into an address
|
||||
*/
|
||||
public static void main(String[] args) throws UnknownHostException {
|
||||
SpringApplication app = new SpringApplication(CarappApp.class);
|
||||
DefaultProfileUtil.addDefaultProfile(app);
|
||||
Environment env = app.run(args).getEnvironment();
|
||||
String protocol = "http";
|
||||
if (env.getProperty("server.ssl.key-store") != null) {
|
||||
protocol = "https";
|
||||
}
|
||||
log.info("\n----------------------------------------------------------\n\t" +
|
||||
"Application '{}' is running! Access URLs:\n\t" +
|
||||
"Local: \t\t{}://localhost:{}\n\t" +
|
||||
"External: \t{}://{}:{}\n\t" +
|
||||
"Profile(s): \t{}\n----------------------------------------------------------",
|
||||
env.getProperty("spring.application.name"),
|
||||
protocol,
|
||||
env.getProperty("server.port"),
|
||||
protocol,
|
||||
InetAddress.getLocalHost().getHostAddress(),
|
||||
env.getProperty("server.port"),
|
||||
env.getActiveProfiles());
|
||||
|
||||
String configServerStatus = env.getProperty("configserver.status");
|
||||
log.info("\n----------------------------------------------------------\n\t" +
|
||||
"Config Server: \t{}\n----------------------------------------------------------",
|
||||
configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.car.app.aop.logging;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Aspect for logging execution of service and repository Spring components.
|
||||
*
|
||||
* By default, it only runs with the "dev" profile.
|
||||
*/
|
||||
@Aspect
|
||||
public class LoggingAspect {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public LoggingAspect(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointcut that matches all repositories, services and Web REST endpoints.
|
||||
*/
|
||||
@Pointcut("within(com.car.app.repository..*) || within(com.car.app.service..*) || within(com.car.app.web.rest..*)")
|
||||
public void loggingPointcut() {
|
||||
// Method is empty as this is just a Pointcut, the implementations are in the advices.
|
||||
}
|
||||
|
||||
/**
|
||||
* Advice that logs methods throwing exceptions.
|
||||
*/
|
||||
@AfterThrowing(pointcut = "loggingPointcut()", throwing = "e")
|
||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
|
||||
log.error("Exception in {}.{}() with cause = \'{}\' and exception = \'{}\'", joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(), e.getCause() != null? e.getCause() : "NULL", e.getMessage(), e);
|
||||
|
||||
} else {
|
||||
log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(), e.getCause() != null? e.getCause() : "NULL");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Advice that logs when a method is entered and exited.
|
||||
*/
|
||||
@Around("loggingPointcut()")
|
||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
|
||||
}
|
||||
try {
|
||||
Object result = joinPoint.proceed();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName(), result);
|
||||
}
|
||||
return result;
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
|
||||
joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.car.app.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Properties specific to JHipster.
|
||||
*
|
||||
* <p>
|
||||
* Properties are configured in the application.yml file.
|
||||
* </p>
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
|
||||
public class ApplicationProperties {
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.car.app.config;
|
||||
|
||||
import io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor;
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.*;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
@EnableScheduling
|
||||
public class AsyncConfiguration implements AsyncConfigurer {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(AsyncConfiguration.class);
|
||||
|
||||
private final JHipsterProperties jHipsterProperties;
|
||||
|
||||
public AsyncConfiguration(JHipsterProperties jHipsterProperties) {
|
||||
this.jHipsterProperties = jHipsterProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean(name = "taskExecutor")
|
||||
public Executor getAsyncExecutor() {
|
||||
log.debug("Creating Async Task Executor");
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
|
||||
executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
|
||||
executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
|
||||
executor.setThreadNamePrefix("carapp-Executor-");
|
||||
return new ExceptionHandlingAsyncTaskExecutor(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return new SimpleAsyncUncaughtExceptionHandler();
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package com.car.app.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
import io.github.jhipster.config.JHipsterProperties;
|
||||
|
||||
import com.hazelcast.config.Config;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.Hazelcast;
|
||||
import com.hazelcast.config.MapConfig;
|
||||
import com.hazelcast.config.EvictionPolicy;
|
||||
import com.hazelcast.config.MaxSizeConfig;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@AutoConfigureAfter(value = { MetricsConfiguration.class })
|
||||
@AutoConfigureBefore(value = { WebConfigurer.class, DatabaseConfiguration.class })
|
||||
public class CacheConfiguration {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CacheConfiguration.class);
|
||||
|
||||
private final Environment env;
|
||||
|
||||
private final DiscoveryClient discoveryClient;
|
||||
|
||||
private final ServerProperties serverProperties;
|
||||
|
||||
public CacheConfiguration(Environment env, DiscoveryClient discoveryClient, ServerProperties serverProperties) {
|
||||
this.env = env;
|
||||
this.discoveryClient = discoveryClient;
|
||||
this.serverProperties = serverProperties;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
log.info("Closing Cache Manager");
|
||||
Hazelcast.shutdownAll();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager(HazelcastInstance hazelcastInstance) {
|
||||
log.debug("Starting HazelcastCacheManager");
|
||||
CacheManager cacheManager = new com.hazelcast.spring.cache.HazelcastCacheManager(hazelcastInstance);
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
|
||||
log.debug("Configuring Hazelcast");
|
||||
Config config = new Config();
|
||||
config.setInstanceName("carapp");
|
||||
// The serviceId is by default the application's name, see Spring Boot's eureka.instance.appname property
|
||||
String serviceId = discoveryClient.getLocalServiceInstance().getServiceId();
|
||||
log.debug("Configuring Hazelcast clustering for instanceId: {}", serviceId);
|
||||
|
||||
// In development, everything goes through 127.0.0.1, with a different port
|
||||
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
|
||||
log.debug("Application is running with the \"dev\" profile, Hazelcast " +
|
||||
"cluster will only work with localhost instances");
|
||||
|
||||
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
|
||||
config.getNetworkConfig().setPort(serverProperties.getPort() + 5701);
|
||||
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
|
||||
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
|
||||
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
|
||||
String clusterMember = "127.0.0.1:" + (instance.getPort() + 5701);
|
||||
log.debug("Adding Hazelcast (dev) cluster member " + clusterMember);
|
||||
config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(clusterMember);
|
||||
}
|
||||
} else { // Production configuration, one host per instance all using port 5701
|
||||
config.getNetworkConfig().setPort(5701);
|
||||
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
|
||||
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
|
||||
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
|
||||
String clusterMember = instance.getHost() + ":5701";
|
||||
log.debug("Adding Hazelcast (prod) cluster member " + clusterMember);
|
||||
config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(clusterMember);
|
||||
}
|
||||
}
|
||||
config.getMapConfigs().put("default", initializeDefaultMapConfig());
|
||||
config.getMapConfigs().put("com.car.app.domain.*", initializeDomainMapConfig(jHipsterProperties));
|
||||
return Hazelcast.newHazelcastInstance(config);
|
||||
}
|
||||
|
||||
private MapConfig initializeDefaultMapConfig() {
|
||||
MapConfig mapConfig = new MapConfig();
|
||||
|
||||
/*
|
||||
Number of backups. If 1 is set as the backup-count for example,
|
||||
then all entries of the map will be copied to another JVM for
|
||||
fail-safety. Valid numbers are 0 (no backup), 1, 2, 3.
|
||||
*/
|
||||
mapConfig.setBackupCount(0);
|
||||
|
||||
/*
|
||||
Valid values are:
|
||||
NONE (no eviction),
|
||||
LRU (Least Recently Used),
|
||||
LFU (Least Frequently Used).
|
||||
NONE is the default.
|
||||
*/
|
||||
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
|
||||
|
||||
/*
|
||||
Maximum size of the map. When max size is reached,
|
||||
map is evicted based on the policy defined.
|
||||
Any integer between 0 and Integer.MAX_VALUE. 0 means
|
||||
Integer.MAX_VALUE. Default is 0.
|
||||
*/
|
||||
mapConfig.setMaxSizeConfig(new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE));
|
||||
|
||||
return mapConfig;
|
||||
}
|
||||
|
||||
private MapConfig initializeDomainMapConfig(JHipsterProperties jHipsterProperties) {
|
||||
MapConfig mapConfig = new MapConfig();
|
||||
mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getHazelcast().getTimeToLiveSeconds());
|
||||
return mapConfig;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.car.app.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cloud.config.java.AbstractCloudConfig;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
@Profile(JHipsterConstants.SPRING_PROFILE_CLOUD)
|
||||
public class CloudDatabaseConfiguration extends AbstractCloudConfig {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CloudDatabaseConfiguration.class);
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource(CacheManager cacheManager) {
|
||||
log.info("Configuring JDBC datasource from a cloud provider");
|
||||
return connectionFactory().dataSource();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.car.app.config;
|
||||
|
||||
/**
|
||||
* Application constants.
|
||||
*/
|
||||
public final class Constants {
|
||||
|
||||
//Regex for acceptable logins
|
||||
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
|
||||
|
||||
public static final String SYSTEM_ACCOUNT = "system";
|
||||
public static final String ANONYMOUS_USER = "anonymoususer";
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.car.app.config;
|
||||
|
||||
import io.github.jhipster.config.JHipsterConstants;
|
||||
import io.github.jhipster.config.liquibase.AsyncSpringLiquibase;
|
||||
|
||||
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
import org.h2.tools.Server;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories("com.car.app.repository")
|
||||
@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
|
||||
@EnableTransactionManagement
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class);
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public DatabaseConfiguration(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the TCP port for the H2 database, so it is available remotely.
|
||||
*
|
||||
* @return the H2 database TCP server
|
||||
* @throws SQLException if the server failed to start
|
||||
*/
|
||||
@Bean(initMethod = "start", destroyMethod = "stop")
|
||||
@Profile(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
|
||||
public Server h2TCPServer() throws SQLException {
|
||||
return Server.createTcpServer("-tcp","-tcpAllowOthers");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SpringLiquibase liquibase(@Qualifier("taskExecutor") TaskExecutor taskExecutor,
|
||||
DataSource dataSource, LiquibaseProperties liquibaseProperties) {
|
||||
|
||||
// Use liquibase.integration.spring.SpringLiquibase if you don't want Liquibase to start asynchronously
|
||||
SpringLiquibase liquibase = new AsyncSpringLiquibase(taskExecutor, env);
|
||||
liquibase.setDataSource(dataSource);
|
||||
liquibase.setChangeLog("classpath:config/liquibase/master.xml");
|
||||
liquibase.setContexts(liquibaseProperties.getContexts());
|
||||
liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema());
|
||||
liquibase.setDropFirst(liquibaseProperties.isDropFirst());
|
||||
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_NO_LIQUIBASE)) {
|
||||
liquibase.setShouldRun(false);
|
||||
} else {
|
||||
liquibase.setShouldRun(liquibaseProperties.isEnabled());
|
||||
log.debug("Configuring Liquibase");
|
||||
}
|
||||
return liquibase;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Hibernate5Module hibernate5Module() {
|
||||
return new Hibernate5Module();
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.car.app.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class DateTimeFormatConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
|
||||
registrar.setUseIsoFormat(true);
|
||||
registrar.registerFormatters(registry);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user