gradle application plugin got shutdown - plugins

I am using gradle application plugin to run my application. Below is my build.gradle:
group 'demo.jersey'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.5
mainClassName = "com.example.Main"
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.22.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
When I run gradle run, I can see my application is launched but it got shutdown immediately. Below is my Main class. Do you know how to block the application without shutting down?
package com.example;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import java.io.IOException;
import java.net.URI;
public class Main {
public static final String BASE_URI = "http://localhost:8080/myapp/";
public static HttpServer startServer() {
final ResourceConfig rc = new ResourceConfig().packages("com.example");
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.stop();
}
}

It stops because you invoke server.stop(); explicitly so the program finishes. Comment out this line and it will keep on running and listening for incoming requests.

Related

Quarkus Reactive WebClient Gives Unsatisfied dependency

I am trying to boot up a simple quarkus app where I can filter the incoming request and check the token in the header. But getting unsatisfied dependency. So any request comes to resource should first get through the requestFilter.java
I want application to build successfully.
Quarkus version 2.16.1.Final, Java 17 and gradle 7.5.1
build.gradle
plugins {
id 'java'
id 'io.quarkus'
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation('io.quarkus:quarkus-arc')
testImplementation('io.quarkus:quarkus-junit5')
testImplementation('io.rest-assured:rest-assured')
implementation('io.quarkus:quarkus-resteasy-reactive')
implementation("io.quarkus:quarkus-rest-client-reactive-jackson")
implementation("io.quarkus:quarkus-kubernetes")
implementation("io.quarkus:quarkus-vertx")
implementation("io.smallrye.reactive:smallrye-mutiny-vertx-web-client")
}
version '1.0-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
test {
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}
compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << '-parameters'
}
compileTestJava {
options.encoding = 'UTF-8'
}
RequestFilter.java
import io.quarkus.runtime.util.StringUtil;
import io.vertx.mutiny.core.Vertx;
import io.vertx.mutiny.ext.web.client.WebClient;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.server.ServerRequestFilter;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.Provider;
#Provider
#ApplicationScoped
public class RequestFilters {
#Inject
UriInfo uriInfo;
#Inject
Logger logger;
private final Vertx vertx;
private final WebClient client;
#Inject
public RequestFilters(Vertx vertx, WebClient client) {
this.vertx = vertx;
this.client = WebClient.create(vertx);
}
private static final String USER_TOKEN_JWT = "usertoken";
#ServerRequestFilter
public void requestFilter(ContainerRequestContext requestContext) throws Exception {
if (StringUtil.isNullOrEmpty(requestContext.getHeaders().getFirst(USER_TOKEN_JWT))) {
logger.error("User token is missing.");
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
var requestUri = uriInfo.getRequestUri().getPath();
client.getAbs(requestUri)
//.host("")
//.port(8080)
.send();
}
}
Exception
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.vertx.mutiny.ext.web.client.WebClient and qualifiers [#Default]
- java member: *.*.*.gateway.RequestFilters():client
- declared on CLASS bean [types=[*.*.*.gateway.RequestFilters, java.lang.Object], qualifiers=[#Default, #Any], target=*.*.*.gateway.RequestFilters]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1223)
Simply changed the order of annotation on requestFilter class and it worked.
#ApplicationScoped
#Provider
#RegisterRestClient
#RegisterClientHeaders
public class RequestFilters {
..
..
}

Spring Cloud Turbine AMQP doesn't working with Hystrix Dashboard

I'm trying to set up spring cloud turbine amqp and hystrix dashboard. But when I start all applications hystrix dashboard doesn't show me anything:
hystrix-dashboard-screenshot-link
But when I open turbine stream link, I see not empty data:
turbine-stream-data-screenshot-link
When I stop my turbine service and run sample: https://github.com/spring-cloud-samples/turbine
It's working:
working-hystrix-dashboard-screenshot-link
So, the problem is in the my turbine service.
This is the TurbineApplication.java:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream;
#EnableTurbineStream
#SpringBootApplication
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
This is the application.yml:
server:
port: ${PORT:8989}
eureka:
user:
name: "{cipher}6c627b546202f13ffa9e3edf39974a3bfca5d615f58dcbfc23065661968b13c5"
password: "{cipher}75efd89c7c4d79220a5b3f35e9ad692a69c820fa0b99e9c48ae9433d45ba016db808ab9dce78382235e529291f8aa0be"
instance:
preferIpAddress: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://${eureka.user.name}:${eureka.user.password}#127.0.0.1:8761/eureka/
This is bootstrap.yml:
spring:
application:
name: turbine-service
And this is gradle.build:
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
dockerPluginVersion = '1.2'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("se.transmode.gradle:gradle-docker:${dockerPluginVersion}")
}
}
apply plugin: 'java'
apply plugin: 'docker'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.pda'
jar {
baseName = 'turbine-service'
version = 'latest'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext {
springCloudVersion = 'Edgware.RELEASE'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-turbine-stream')
compile('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task buildDocker(type: Docker, dependsOn: build) {
push = false
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
It looks like the problem is in the dependencies version.
The problem is in the Edgware.RELEASE (and Edgware.SR1) version. It's need to downgrade spring cloud version (for example, to Dalston.SR5), or use Edgware.BUILD-SNAPSHOT.
Description: https://github.com/spring-cloud/spring-cloud-netflix/issues/2637

Why do I get "Duplicate XML entry" when I try to run my jHipster app as a stand-alone war (built by gradlew bootRepackage)?

I am stumped by this one so I'm looking for some help here.
I am developing a jHipster app with multiple database connections, built with gradle. The app runs fine with "./gradlew bootRun" but when I try to package a stand-alone war with "./gradlew -Pprod bootRepackage" and run it, I get this exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/babycenter/belle/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Duplicate XML entry for com.babycenter.belle.readonly.domain.InvoiceLineItem
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at com.babycenter.belle.BelleApp.main(BelleApp.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: java.lang.IllegalStateException: Duplicate XML entry for com.babycenter.belle.readonly.domain.InvoiceLineItem
at org.hibernate.cfg.annotations.reflection.XMLContext.addClass(XMLContext.java:140)
at org.hibernate.cfg.annotations.reflection.XMLContext.addDocument(XMLContext.java:105)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.<init>(AnnotationMetadataSourceProcessorImpl.java:94)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.<init>(MetadataBuildingProcess.java:147)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:141)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 22 common frames omitted
I am puzzled because the file it says the error is in, DatabaseConfiguration.java, should only read entities from the package com.babycenter.belle.domain, which the class/XML it says is duplicated, InvoiceLineItem, is not in.
Here are files that may be involved. Tell me if you would like to see another.
DatabaseConfiguration.java
package com.babycenter.belle.config;
import io.github.jhipster.config.JHipsterConstants;
import io.github.jhipster.config.liquibase.AsyncSpringLiquibase;
import liquibase.integration.spring.SpringLiquibase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
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.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
#Configuration
#EnableJpaRepositories(basePackages = "com.babycenter.belle.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;
}
#Bean
public SpringLiquibase liquibase(#Qualifier("taskExecutor") TaskExecutor taskExecutor, #Qualifier("dataSource") DataSource dataSource,
LiquibaseProperties liquibaseProperties) {
// Start Liquibase asynchronously
SpringLiquibase liquibase = new AsyncSpringLiquibase(taskExecutor, env);
// Start Liquibase synchronously
//SpringLiquibase liquibase = new SpringLiquibase();
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;
}
#Primary
#Bean(name = "dataSource")
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Primary
#Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, #Qualifier("dataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("com.babycenter.belle.domain")
.persistenceUnit("readwrite")
.build();
}
#Primary
#Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(#Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
ReadOnlyDatabaseConfiguration.java
package com.babycenter.belle.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
#Configuration
#EnableJpaRepositories(
entityManagerFactoryRef = "roEntityManagerFactory",
transactionManagerRef = "roTransactionManager",
basePackages = "com.babycenter.belle.readonly.repository")
#EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
#EnableTransactionManagement
public class ReadOnlyDatabaseConfiguration {
private final Logger log = LoggerFactory.getLogger(ReadOnlyDatabaseConfiguration.class);
#Bean(name = "roDataSource")
#ConfigurationProperties(prefix = "spring.datasource-ro")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "roEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean roEntityManagerFactory(EntityManagerFactoryBuilder builder, #Qualifier("roDataSource") DataSource dataSource) {
return
builder
.dataSource(dataSource)
.packages("com.babycenter.belle.readonly.domain")
.persistenceUnit("readonly")
.build();
}
#Bean(name = "roTransactionManager")
public PlatformTransactionManager roTransactionManager(#Qualifier("roEntityManagerFactory") EntityManagerFactory roEntityManagerFactory) {
return new JpaTransactionManager(roEntityManagerFactory);
}
}
InvoiceLineItem.java
package com.babycenter.belle.readonly.domain;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
/**
* An object representation of a row from the opr_invoice_line_item table in Redshift
*/
#Entity
#Table(name = "opr_invoice_line_item", schema = "advertising")
#Cacheable
#Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class InvoiceLineItem implements Serializable {
#Id
#Column(name = "invoice_line_item_id", insertable = false, updatable = false)
private Long invoiceLineItemId;
#Column(name = "sales_order_line_item_id", insertable = false, updatable = false)
private Long salesOrderLineItemId;
#Column(name = "primary_performance", insertable = false, updatable = false)
private Long primaryPerformance;
#Column(name = "third_party_performance", insertable = false, updatable = false)
private Long thirdPartyPerformance;
#Column(name = "invoice_units", insertable = false, updatable = false)
private String invoiceUnits;
#Column(name = "invoice_amount", insertable = false, updatable = false)
private Float invoiceAmount;
/**
* Assigned when possible - not a column in opr_invoice_line_item table
*/
private String billingPeriodName;
public Long getInvoiceLineItemId() {
return invoiceLineItemId;
}
public void setInvoiceLineItemId(Long invoiceLineItemId) {
this.invoiceLineItemId = invoiceLineItemId;
}
public Long getSalesOrderLineItemId() {
return salesOrderLineItemId;
}
public void setSalesOrderLineItemId(Long salesOrderLineItemId) {
this.salesOrderLineItemId = salesOrderLineItemId;
}
public Long getPrimaryPerformance() {
return primaryPerformance;
}
public void setPrimaryPerformance(Long primaryPerformance) {
this.primaryPerformance = primaryPerformance;
}
public Long getThirdPartyPerformance() {
return thirdPartyPerformance;
}
public void setThirdPartyPerformance(Long thirdPartyPerformance) {
this.thirdPartyPerformance = thirdPartyPerformance;
}
public String getInvoiceUnits() {
return invoiceUnits;
}
public void setInvoiceUnits(String invoiceUnits) {
this.invoiceUnits = invoiceUnits;
}
public Float getInvoiceAmount() {
return invoiceAmount;
}
public void setInvoiceAmount(Float invoiceAmount) {
this.invoiceAmount = invoiceAmount;
}
public String getBillingPeriodName() {
return billingPeriodName;
}
public void setBillingPeriodName(String billingPeriodName) {
this.billingPeriodName = billingPeriodName;
}
}
build.gradle
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
jcenter()
maven { url "http://repo.spring.io/plugins-release" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
classpath "org.springframework.build.gradle:propdeps-plugin:0.0.7"
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "org.sonarqube" version "2.5"
id "net.ltgt.apt" version "0.11"
id "io.spring.dependency-management" version "1.0.3.RELEASE"
id "com.moowork.node" version "1.2.0"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
apply plugin: 'java'
sourceCompatibility=1.8
targetCompatibility=1.8
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'propdeps'
apply plugin: 'com.moowork.node'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
defaultTasks 'bootRun'
group = 'com.babycenter.belle'
version = '0.0.1-SNAPSHOT'
description = ''
bootRepackage {
mainClass = 'com.babycenter.belle.BelleApp'
}
war {
}
springBoot {
mainClass = 'com.babycenter.belle.BelleApp'
executable = true
buildInfo()
}
if (OperatingSystem.current().isWindows()) {
task pathingJar(type: Jar) {
dependsOn configurations.runtime
appendix = 'pathing'
doFirst {
manifest {
attributes 'Class-Path': configurations.runtime.files.collect {
it.toURL().toString().replaceFirst(/file:\/+/, '/').replaceAll(' ', '%20')
}.join(' ')
}
}
}
bootRun {
addResources = false
dependsOn pathingJar
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", pathingJar.archivePath)
}
}
} else {
bootRun {
addResources = false
systemProperties System.properties
}
}
//use jrebel to hot-deploy class changes during development
if (project.hasProperty('rebelAgent')) {
bootRun.jvmArgs += rebelAgent
}
test {
include '**/*UnitTest*'
include '**/*IntTest*'
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task cucumberTest(type: Test) {
include '**/CucumberTest*'
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
test.finalizedBy(cucumberTest)
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
reportOn cucumberTest
}
cucumberTest.finalizedBy(testReport)
apply from: 'gradle/docker.gradle'
apply from: 'gradle/sonar.gradle'
apply from: 'gradle/liquibase.gradle'
apply from: 'gradle/mapstruct.gradle'
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty('prod')) {
apply from: 'gradle/profile_prod.gradle'
} else if (project.hasProperty('stag')) {
apply from: 'gradle/profile_stag.gradle'
} else {
apply from: 'gradle/profile_dev.gradle'
}
if (project.hasProperty('graphite')) {
apply from: 'gradle/graphite.gradle'
}
if (project.hasProperty('prometheus')) {
apply from: 'gradle/prometheus.gradle'
}
configurations {
providedRuntime
compile.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
jcenter()
maven { url 'http://nexus.babycenter.com:8081/nexus/content/repositories/thirdparty/'}
}
dependencies {
compile "io.github.jhipster:jhipster:${jhipster_server_version}"
compile "io.dropwizard.metrics:metrics-core:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-jcache:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-jvm:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-servlet:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-json:${dropwizard_metrics_version}"
compile "io.dropwizard.metrics:metrics-servlets:${dropwizard_metrics_version}"
compile "net.logstash.logback:logstash-logback-encoder:${logstash_logback_encoder_version}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-csv:${jackson_dataformat_csv_version}"
compile "com.fasterxml.jackson.datatype:jackson-datatype-json-org"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
compile "com.fasterxml.jackson.core:jackson-annotations"
compile "com.fasterxml.jackson.core:jackson-databind"
compile "com.fasterxml.jackson.module:jackson-module-afterburner"
compile ("com.ryantenney.metrics:metrics-spring:${metrics_spring_version}")
compile "javax.cache:cache-api"
compile "org.hibernate:hibernate-core:${hibernate_version}"
compile ("com.zaxxer:HikariCP:${hikaricp_version}")
compile "org.apache.commons:commons-lang3:${commons_lang_version}"
compile "commons-io:commons-io:${commons_io_version}"
compile "javax.transaction:javax.transaction-api"
compile "org.ehcache:ehcache"
compile "org.hibernate:hibernate-jcache:${hibernate_version}"
compile "org.hibernate:hibernate-envers:${hibernate_version}"
compile "org.hibernate:hibernate-validator"
compile "org.hibernate:hibernate-entitymanager:${hibernate_version}"
compile ("org.liquibase:liquibase-core")
compile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"
compile "org.springframework.boot:spring-boot-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-loader-tools"
compile "org.springframework.boot:spring-boot-starter-mail"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-aop"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-security"
compile ("org.springframework.boot:spring-boot-starter-web") {
exclude module: 'spring-boot-starter-tomcat'
}
compile "org.springframework.boot:spring-boot-starter-undertow"
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
compile "org.zalando:problem-spring-web:${problem_spring_web_version}"
compile "org.springframework.boot:spring-boot-starter-cloud-connectors"
compile ("org.springframework:spring-context-support")
compile "org.springframework.security:spring-security-config"
compile "org.springframework.security:spring-security-data"
compile "org.springframework.security:spring-security-web"
compile ("io.springfox:springfox-swagger2:${springfox_version}") {
exclude module: 'mapstruct'
}
compile "io.springfox:springfox-bean-validators:${springfox_version}"
//The Data Warehouse (i.e. our read-only data source) is AWS Redshift
compile "com.amazon.redshift:RedShiftJDBC42:${redshift_jdbc_version}" //needs the RedShiftJDBC42 driver to work
compile "com.amazonaws:aws-java-sdk-redshift:${redshift_sdk_version}"
//our writable database is mysql
compile "mysql:mysql-connector-java"
compile "org.mapstruct:mapstruct-jdk8:${mapstruct_version}"
testCompile "org.awaitility:awaitility:${awaitility_version}"
testCompile "com.jayway.jsonpath:json-path"
testCompile "info.cukes:cucumber-junit:${cucumber_version}"
testCompile "info.cukes:cucumber-spring:${cucumber_version}"
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
testCompile "org.springframework.security:spring-security-test"
testCompile "org.springframework.boot:spring-boot-test"
testCompile "org.assertj:assertj-core:${assertj_version}"
testCompile "junit:junit"
testCompile "org.mockito:mockito-core"
testCompile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"
testCompile "org.hamcrest:hamcrest-library"
testCompile "com.h2database:h2"
optional ("org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}") {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
clean {
delete "target"
}
task cleanResources(type: Delete) {
delete 'build/resources'
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
task stage(dependsOn: 'bootRepackage') {
}
if (project.hasProperty('nodeInstall')) {
node {
version = "${node_version}"
npmVersion = "${npm_version}"
yarnVersion = "${yarn_version}"
download = true
}
}
compileJava.dependsOn processResources
processResources.dependsOn cleanResources,bootBuildInfo
bootBuildInfo.mustRunAfter cleanResources
Here are my versions of things:
jHipster 4.9.0
Spring Boot 1.5.8.RELEASE
Gradle 4.2
Groovy 2.4.11
I was eventually able to solve this myself.
I was using annotations in code to define my JPA entities PLUS an orm.xml file for named queries that had to have my result class entities defined. I had no persistence.xml file.
This ran fine with “./gradlew bootRun” but when I bundled a war it threw the exception listed above.
I learned when I package up a Spring Boot war with Hibernate JPA it will attempt to add annotated entities to orm.xml - and may even load orm.xml multiple times:
Duplicate XML entry | Hibernate orm.xml
Since I already had an entity definition there, it said there was a duplicate.
Basically I learned I can either use annotations in code, including named queries, OR define everything in orm.xml but I can’t mix the two.

Unable to execute jar file in a ubuntu server

I have a small sqoop import project where i have to import from mysql to hdfs. It is a maven project, while i am running in my local system it works fine. Now when i am trying to run in my ubuntu server by running a jar file, it is executing but not showing any output. It is not a web based application, normal application where i am running hadoop deamons and running this project. Tell me how to run this type of projects in servers and run.
package org.ezytruk.sqoop;
import java.io.FileInputStream;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.sqoop.tool.ImportTool;
import com.cloudera.sqoop.SqoopOptions;
import com.cloudera.sqoop.SqoopOptions.FileLayout;
public class SqoopImport {
public static void importMySQLToHDFS() throws Exception {
try {
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver).newInstance();
Configuration config = new Configuration();
config.addResource(new Path("/usr/local/hadoop/etc/hadoop/conf/core-site.xml"));
config.addResource(new Path("/usr/local/hadoop/etc/hadoop/conf/hdfs-site.xml"));
Properties properties = new Properties();
properties.load(new FileInputStream("/home/*****/SqoopImportHDFS/resources/sqoopImport.properties"));
//org.apache.sqoop.SqoopOptions sqoopOptions = new org.apache.sqoop.SqoopOptions();
SqoopOptions sqoopOptions = new SqoopOptions();
sqoopOptions.setDriverClassName(driver);
sqoopOptions.setHadoopHome("/usr/local/hadoop");
sqoopOptions.setConnectString(properties.getProperty("db_mysql_connection_string"));
sqoopOptions.setTableName(properties.getProperty("db_mysql_table_name"));
sqoopOptions.setUsername(properties.getProperty("db_mysql_username"));
sqoopOptions.setPassword(properties.getProperty("db_mysql_password"));
sqoopOptions.setNumMappers(1);
//sqoopOptions.setWarehouseDir(properties.getProperty("db_hdfs_warehouse_directory"));
sqoopOptions.setTargetDir(properties.getProperty("db_hdfs_output_directory"));
sqoopOptions.setFileLayout(FileLayout.TextFile);
new ImportTool().run(sqoopOptions);
} catch (Exception e) {
}
}
public static void main(String[] args) throws Exception {
SqoopImport mySqlImport = new SqoopImport();
mySqlImport.importMySQLToHDFS();
}
}

Lombok Usage - It doesn't serve its functionality in a unit test

A domain object is setup as the following:
#Data
#NoArgsConstructor
#Entity
public class Foo {
...
public Foo(...){
...
}
...
}
It is fine when I run a build with a set of tests. When I only run the test class, however, I get the following error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: No default constructor for entity: : com.abc.myapp.Foo; nested exception is org.hibernate.InstantiationException: No default constructor for entity: : com.abc.myapp.Foo
The project setup is with Spring Boot generated by the project generator on spring.io. And the following is the Gradle build file:
buildscript {
ext {
springBootVersion = '1.5.0.RC1'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'spring-data-samples'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}
And IDE is Intellij Idea.
What is missing?