AspectJ and Springboot not working together - aspectj

In my project i want to use pure aspectj in combination with spring-boot
While configuring the project we ran into some issues.
Found another similar problem but that doesnt help us.
This is what we did:
got springboot project
defined 2 aspects, 1 simple spring main class
added aspectj plugin to gradle build
set applicationDefaultJvmArgs to use the javaagent for aspectjweaver
Here is a link to our repo at github. https://github.com/svenhornberg/MDSD
and here is the Travis-CI build log https://travis-ci.org/svenhornberg/MDSD/builds
But it's still not working like it should.
Think i need some help here.

You seem to be trying to mix compile-time weaving and load-time weaving of your classes. You should chose one approach and use it consistently.
If you want to go with compile-time weaving, remove #EnableLoadTimeWeaving from Application and update build.gradle to remove the configuration of applicationDefaultJvmArgs. There's other clean up that you could do, but these two changes should be sufficient to get your app up and running. With these changes in place, at startup I see it output:
1
Please use List instead of a concrete implementation for method: findByPrio.
[]
Please use List instead of a concrete implementation for method: returnTest.
You used a method with only one boolean parameter. Refactor it into 2 methods with True, False at the end.
true

Related

Get Jenkins plugin dependencies auto installed

I'm developing Jenkins' plugin which is dependent on another plugin (specifically MultiJob plugin, but it can be any other one of course).
Obviously, the dependency is found in POM, so I can actually use the classes of it.
The problem: if I'm trying to install my plugin in Jenkins that the dependency is not found in it Jenkins doesn't installs it automatically and upon first usage my plugin throws an exception NoClassDefFoundError, of course.
Question: can I make Jenkins to install my dependencies as prerequisites and if yes, how?
Note: I do see that other plugins somehow cause the dependencies to be installed (Git plugin for instance makes GitClient installed during its installation).
Thanks in advance.
It's been a while since i've raised the question, but if anybody will look for something similar, here is what i've finally came up with:
Since the dependency classes are only needed in case they are really there, i've decided to use Java's lazy linkage behavior and actually refer the relevant classes only on demand.
So practically, made a factory that has a list of class names of interest and every time i need to process some object i'm checking it's class against this list. If matched - the class is loaded and therefore it's okay to init the linking/initiation logic.
Last one, if you plan to use such a pattern do not forget to sign those dependency plugins as optional in your pom.xml.

Where should JUnit specific Guice module be configured?

I'm going to start using dependency injection in my Eclipse plugin. My test plugin depends on the main one and should use different injection context. Production should work fine standalone (it should have its own injection context), but behave differently when used from tests (should use Junit's injection context).
How could I resolve the injector so that a different one is used in production and in tests?
I don't like the idea to somehow inject context manually in a static variable on test start. Is there a better way? Can extensions be somehow used for that?
I know that in e4 there is a solution for that, but I'm bound to Eclipse Indigo for now and could not find quickly how exactly is that done in latest version. A link to injector configuration with an ability to override in test infrastructure in e4 source is appreciated.
I wound up writing my own JUnit runner modeled largely after the Spring JUnit runner, but would highly recommend looking at the Jukito project now.
At this point I try to have one Guice module per feature, so I end up with one Guice module for test that installs the production module and overrides or binds any external dependencies. I keep that test module in a base test class along with the necessary annotation for the JUnit runner, which is very similar to the JukitoModule examples in the link above.

GWT blamed RequestFactory ValidationTool must be run on on sub module(project) when launching main project

GWT 2.5.0/Google Plugin for Eclipse/m2e/GWT-maven-plugin 2.5.0/Request Factory
I configs my project according to the GWT wiki working with maven and it works pretty well, but has some trouble in my sub-project.
Suppose i have two project A and B, A is a standard GWT project, B is sub-project and has one GWT module, it contains some common UI widgets and some common Entity proxies and RequestFactory, A project depends on B project through Maven dependency, and also in A's Module.gwt.xml, there is an inheritance on B module.
The problem is when i try to lauching A project using GPE, it blames:
The RequestFactory ValidationTool must be run for the … XXXRequestFactory type
where the XXXRequestFactory is in B project. I have to close project B in Eclipse, so it will not blames, this is cumbersome when i want to modify something in B project which used in A to see the changes, i have to close B then see the changes, then open B and made changes...
I wonder if there is a way to solve this problem so my life would be easier.
Thanks.
One more thing, i also use maven-processor-plugin and build-helper-maven-plugin in project B, and make sure the goals are run when i call maven install on B, but seems no help.
I also had this problem and here is the solution which fixed this issue. This answer assumes that you need to execute the GWT app in dev mode (as you mentioned you tried with gwt eclipse plugin)
You may already know this RequestFactory must validate the interfaces, domain types and proxies before execution. So you need to enable annotation processing for this which creates mapping data for server side components in addition to said validation. If this process not succeeded it will throw the error you mentioned.
You can enable the requestfactory validation for project B in the project properties. Go to compiler properties, enable annotation processing providing the path to requestfactory-apt.jar. After this when you compile the project you can see the .apt_generated in your project home dir containing mapping files. If you open one of them you can see generated mappings for your proxies.
Launch the application (project A in your case) and it should run without any errors
In Maven world you have to specify the dependency for this apt jar. In addition to this you might get compiler errors in those generated classes when doing mvn compile, to resolve that simply delete the content in .apt_generated.

Use a java class from a referenced project on the server-side?

I have a GWT project, and I want to use some classes server-side from another project:
MyServerProject
com.me.myserverproject.server.Horse
SomeSupportProject
com.me.somesupportproject.server.Animal
and MyServerProject Horse.java looks like:
class Horse extends Animal {
}
In eclipse, I have MyServerProject referencing the SomeSupportProject project. All compiles fine, and GWT Compile runs fine too, no errors.
When I deploy MyServerProject to a local instance, it immediately throws a NoClassDefFoundError error on "Animal.java":
java.lang.NoClassDefFoundError: com/me/somesupportproject/server/Animal
at java.lang.ClassLoader.defineClass1(Native Method)
I marked SomeSupportProject as exported in the eclipse project properties. But it seems like the class file for Animal.java is not getting exported upon deploy. Do we need to do something special here to get that to work?
I must be missing something really obvious since this is pretty basic stuff. I have clientside java files being referenced just fine, which I think is the trickier case. But these are all server-side classes, thought it would be simpler,
Thanks
------- Update: Project Setup ---------------
Some notes on my environment:
Using eclipse, and the two projects are side by side. I'm not using Ant or Maven. I have eclipse set to build automatically, so not getting any compiler errors there. To actually compile for a deploy, I tried right clicking "MyServerProject", choose Google -> GWT Compile. I set output to "all". I don't get any compile errors. The output does not mention any warnings.
After GWT Compile is complete, I right-click the project again, choose Run As -> Web Application. This is what throws the java.lang.NoClassDefFoundError for the class found in the SomeSupportProject project.
If there any specifics that would help just let me know.
--------- Final Update: Solved -----------------
After working on this some more, it seems we just can't add a project reference and get server-side classes to come across in the deployed top-level project. Instead, I linked to the "src" folder in SomeSupportProject. This allows things to still compile as normal, but when you deploy your project, all the classes are found without issue.
So this was really an app-engine issue, should have tagged it under there instead.
Thanks!
After working on this some more, it seems we just can't add a project reference and get server-side classes to come across in the deployed top-level project. Instead, I linked to the "src" folder in SomeSupportProject. This allows things to still compile as normal, but when you deploy your project, all the classes are found without issue.
So this was really an app-engine issue, should have tagged it under there instead.
Thanks!

What are best practices for using Hibernate's hbm2java?

I am using Hibernate, Maven, and Eclipse (STS build) to build a project. I'm using hbm.xml files to specify my schema. I want to use Hibernate's hbm2java to generate my model classes. I have it working well and generating the kind of code I want.
It runs perfectly from the command line, generating the model code and then building and testing as expected.
However, Eclipse seems unable to handle it. It will periodically "lose its mind" and be unable to resolve very simple imports and classes referenced in my DAO classes, which are hand-coded. The things it can't find are classes like HibernateUtil. Ironically, it appears to not have any trouble finding the model classes.
The unresolved classes are in target/classes/blah-blah folder at the end of the run. So they're apparently getting copied to the right place.
In a "continuous integration" environment, is it best to generate the sources once, commit them to my version control, and then disable code gen? Or is it possible to have the code generated each time, thus ensuring I pick up any database changes without human intervention?
IMHO, entities should be the core of your application, and should be designed, implemented and documented with care. They're supposed to be objects, with methods encapsulating behavior. Having them autogenerated is an absurdity, IMO.
Generating them at the very beginning might be an option to get you started, but once they've been generated, hand-craft them and don't generate them again. Add necessary properties and methods as the schema changes, and refactor existing code.
BTW, I really prefer using annotations for the mapping, because it's less verbose, less error-prone, and all the information is in a single place.
Try this:
From command line traverse to your project directory where the project's pom.xml is present and run:
mvn eclipse:clean eclipse:eclipse
If it says unable to find plugin eclipse then try:
mvn eclipse:install-plugin
First and then try the command above again.
In this way all the maven and project dependencies will be resolved at eclipse level also.
Let me know if this is not what you were looking for.