Jhipster generated code after the error, Mapper could not be found - jhipster

2016-10-20 18:03:51.253 WARN 17216 --- [ restartedMain] .s.c.a.CommonAnnotationBeanPostProcessor : Invocation of destroy method failed on bean with name 'cacheConfiguration': java.lang.NullPointerException
2016-10-20 18:03:51.274 WARN 17216 --- [ restartedMain] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined)
2016-10-20 18:03:51.749 ERROR 17216 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Field countryMapper in com.bosheng.java.service.impl.CountryServiceImpl required a bean of type 'com.bosheng.java.service.mapper.CountryMapper' that could not be found.
Action:
Consider defining a bean of type 'com.bosheng.java.service.mapper.CountryMapper' in your configuration.

If you are using IDEA and Maven, you need to activate the IDE profile in IntelliJ. This is used for applying IDE-specific tweaks which currently only includes applying the MapStruct annotation processor.
Open the “Maven Projects” tool window (View -> Tool Windows), check the IDE maven profile to activate it

I had a similar problem, but using Maven and Eclipse. At the end I realized that I hadn't read well the bottom of the "Configuring your IDE" page from jHipster docs, which says about MapStruct, but I also had to add the target/generated-sources folder to my build path (as instructed on http://g00glen00b.be/mapstruct/ ).

I have tried all the above solutions and followed the jHipster IDE configuration and my problem still not fixed.
That's what solved my problem:
mvnw clean
mvnw compile
For Gradle:
gradlew clean
gradlew compileJava
then refresh the project in the IDE and run it.

I had this issue and it was only an issue with my pom.xml. I needed to add mapstruct to the maven compiler plugin like so:
...
<properties>
<mapstruct.version>1.1.0.Final</mapstruct.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
</properties>
...
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>

Please, next time, add the command line you use to build / launch your app and use code format, in order to have a good format for your question. ;o)
So, according to this log, I suggest you to use IDE and dev maven profil.
I am quite sure you don't use it, so mapstruct have the interface for bean but not generated the implementation classes.

Related

PIT-Cucumber plugin not finding scenarios in feature files

Try to institue PIT Mutation testing in a enterprise project. Got it to do existing JUNit tests, but we also have a lot of Cucumber tests that need to be part of the metric. Added pit-cucumber plugin to the maven project, but the output is no scenarios found. Not sure if there is some secret in the config of the plugin that I can't see.
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.4.7</version>
<configuration>
<testPlugin>Cucumber</testPlugin>
<targetClasses>
<param>org.tiaa.srk.eligibility.*</param>
</targetClasses>
<targetTests>
<param>org.tiaa.srk.eligibility.EligibilityTestRunnerIT</param>
</targetTests>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>com.github.alexvictoor</groupId>
<artifactId>pitest-cucumber-plugin</artifactId>
<version>0.8</version>
</dependency>
</dependencies>
</plugin>
I get this output:
INFO : Sending 0 test classes to minion
Make sure you're using Cucumber version 4.20 jars with pitest-cucumber-plugin 0.8
Everything else looks good. You may not need to specify targetClasses and targetTests.

log4j2 confguration file location when using jetty maven plugin

My application uses log4j2 and we have two of them one for production and another for development environment. I am using maven to run the application using mvn clean jetty:run. My plugin configuration in pom.xml looks like this:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.8.v20171121</version>
<configuration>
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>${log4j-dev.location}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
But my app still uses the log4j2.xml present in the WEB-INF/classes directory instead of the one in the log4j-dev.location path. Any ideas?
I found the solution for this problem. In the webdefault.xml file, I had to add the following code:
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2-custom.xml</param-value>
</context-param>
Hope it helps somebody who spent a whole day looking everywhere like me :)

Error assembling WAR - webxml attribute is required

I'm hitting the following with a jhipster app when running the ./mvnw build:
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
This regression for microservices has been reported in 4.11.0 and fixed: https://github.com/jhipster/generator-jhipster/pull/6742. New release should be available tonight.
In the meantime you can fix it in your own pom.xml by setting failOnMissingWebXml to false:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>

Jhipster executable jar with undertow does not work - 404

I built a jhipster application. Added an entity. Built it with
mvn -Pprod package
Application runs fine with tomcat when I use
java -jar xyz.war
But, since we need Undertow for high load scenarios and fast startup time, I simply change the maven dependency from Tomcat to Undertow in all the places (all the profiles) wherever tomcat starter dependency was mentioned as per the Spring documentation : Using Undertow in Place of Tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
This runs fine when run from Eclipse and I can see the requests are now served by Undertow and not Tomcat as logs print XNIO as the thread-id.
But., when I again build it and try to run it with java -jar xyz.war,
Application boots up fine but when I hit the URLs
http://127.0.0.1:8081
or http://127.0.0.1/xyz
it says not found.
What else do I need to do to put jHipster application with Undertow embedded to work?
Any quick help appreciated as a critical POC to push jHipster in our organization hinges on this step.
We used to support Undertow, but removed it recently. So you shouldn't have much trouble setting it up back (and what you do looks good, then you don't post your whole configuration so it's hard to tell).
Anyway, concerning your specific use-case, you need to know why we removed Undertow:
Start-up time is indeed lower, by something like 300-500ms. We were mostly using this in our "dev" profile, as start-up time is important. But now that we have the Spring Dev Tools hot restart, this isn't useful at all anymore.
For "prod" usage, I haven't seen any performance difference between Tomcat and Undertow. Compared to just one database access (costing several ms), I guess you can't see this kind of improvements.
Besides, we have removed Undertow because it lacks a number of important features for us. Most importantly:
GZip compression support -> as you will lose this, your performance will in fact be much worse with Undertow than with Tomcat
Websocket support
Last but not least, it's easy to scale up your JHipster application by adding new nodes (and it will be even easier in JHipster 3.0), so handling a large number of users shouldn't be an issue.
I didn't manage to have your error. Undertow seems to work fine for me.
1) I generated a new JHipster project (from master), all default options
2) I replace tomcat by undertow only in this part of pom.xml :
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- log configuration -->
<logback.loglevel>DEBUG</logback.loglevel>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
<profile>
<id>prod</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
3) Build :
mvn package -Pprod
4) Start database :
docker-compose -f src/main/docker/prod.yml up -d
5) Start app
java -jar target/*.war --spring.profiles.active=prod
:: JHipster 🤓 :: Running Spring Boot 1.3.2.RELEASE ::
:: http://jhipster.github.io ::
2016-02-22 00:18:40.051 INFO 6118 --- [ main] com.mycompany.myapp.JhundertowApp : Starting JhundertowApp on pgrXps with PID 6118 (started by pgrimaud in /home/pgrimaud/workspace/tests2/32-undertow)
2016-02-22 00:18:40.054 INFO 6118 --- [ main] com.mycompany.myapp.JhundertowApp : The following profiles are active: prod
2016-02-22 00:18:44.024 WARN 6118 --- [ main] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2016-02-22 00:18:44.126 WARN 6118 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2016-02-22 00:18:44.742 INFO 6118 --- [ main] c.mycompany.myapp.config.WebConfigurer : Web application configuration, using profiles: [prod]
6) I change log in app to confirm it runs with undertow
----------------------------------------------------------
Application 'jhundertow' is running! Access URLs:
Local: http://127.0.0.1:8080
External: http://127.0.1.1:8080
----------------------------------------------------------
2016-02-22 00:20:20.585 TRACE 6118 --- [ XNIO-2 task-31] c.m.m.c.l.AngularCookieLocaleResolver : Parsed cookie value [%22en%22] into locale 'en'
2016-02-22 00:20:25.741 TRACE 6118 --- [ XNIO-2 task-32] c.m.m.c.l.AngularCookieLocaleResolver : Parsed cookie value [%22en%22] into locale 'en'
Fortunately for me, when I move the same war file to a RHEL system, it works just fine. :-) I am accepting #pgrimaud 's answer. Thanks #deepu and #Julien. You guys are awesome.
I will investigate what's going wrong on my Win7 machine-will post back here if I am able to figure out. (npm clear cache dint help. Will re-install node.js and npm as I had updated them for my other node.js work - I will see if that helps). I will also try to debug spring-boot-starter-undertow.
Finally, a solution for the nemesis is in place. Here is an update from me - Today, I started to debug spring boot and undertow code and realized that spring boot is looking for resources in the below locations :
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" };
After that, I created a folder called resources inside the META-INF directory and copied all the resources inside it using 7zip. And lo & behold., it works! :-).
Although spring boot is supposed to also load resources from
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
for some reason, it is not doing so. (which is where jHipster is putting all of the resource files)
I thought this to be a bug with spring boot version that jHipster uses and I upgraded my app spring boot version to 1.3.3.RELEASE , but that does not help either.

Deploying an eclipse maven project in a remote linux server's tomcat

I'm looking a way to deploy a maven project developed using eclipse in a remote linux server's tomcat. I know you can export it as a .war file and dump it in CATALINA_HOME/webapps folder of the remote server. But for that you have to first export it to .war file and then copy the .war file in to remote server through SFTP or SCP. I'm looking for a way to do it with few clicks using eclipse or/and configuring some maven settings(in pom.xml or settings.xml). Does any one know how to do this? Any help is really appreciated.
The tool you are loooking for is called Tomcat Maven Plugin
What it basically does is it uses the API of Tomcat manager application, which you have to make sure is deployed on the Tomcat instance you are using. By default Tomcat manager should be available in the following location:
http://ip_of_your_linux_server:8080/manager/html
If it is not, please install it using the following command:
sudo apt-get install tomcat6-admin
You can configure the location of your Tomcat instance as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://www.mydomain.com:1234/mymanager</url>
</configuration>
</plugin>
and then run maven mvn tomcat:deploy goal. (Either from command line of from Eclipse using m2Eclipse plugin.)
Please refer to configuration and deployment pages of the plugin for more verbose information.
The most flexible solution with adapters for many different containers like Tomcat, Jetty, Glassfish, etc. is probably Maven Cargo plugin. You can find an extensive list of examples on their homepage, so no need to paste that here again.
To remotely deploy an application you'll need to configure the tomcat deployer app on the tomcat instance. Be warned, the configuration of admin users has undergone some subtle changes between tomcat 6 and 7.
Once this is working the Maven cargo plugin can deploy war files as follows:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>tomcat-deploy</id>
<phase>package</phase>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.uri>${tomcat.manager.url}</cargo.remote.uri>
<cargo.remote.username>${tomcat.manager.user}</cargo.remote.username>
<cargo.remote.password>${tomcat.manager.pass}</cargo.remote.password>
</properties>
</configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
<properties>
<context>${project.artifactId}</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Additional notes
The Cargo plugin supports several different containers, problem is the doco is difficult to interpret.
I haven't used the Maven plugin. It's very new

Resources