I am deploy an project Spring Boot, using devtools(spring-boot-devtools) and call a Soap service.
I generate the Soap class into /src/main/resources/templates/generated
and add this folder as Source Code.
Because when call this Soap service, its have a problem:
java.lang.IllegalArgumentException: ...ClassV11PortType referenced from a method is not visible from class loader
So, I was add the spring-devtools.properties file to /src/main/resources/META-INF/spring-devtools.properties
and add this line to spring-devtools.properties file:
restart.exclude.mygeneratedclasses=/[packageOfGeneratedClass].class
Then now, I can call the SOAP service successful.
But now, my project cannot reload automatically when i modified some code.
I was try to edit some code anywhere and save but not luck, my project doesnot reload.
Instead of excluding generated files, you can try to include JAR responsible for loading these classes into restart classloader (used in spring-devtools).
For dependency com.sun.xml.ws:jaxws-rt:2.3.2-1, update /src/main/resources/META-INF/spring-devtools.properties like this:
restart.include.jax=/jaxws-rt.*\.jar
Github issue reference: Devtools cannot be use with jaxws-ri #19379
Related
Currently I have quite a bit of services written in Spring Boot 2.1.3 (in mono-repo) and I have a common package that's used in most of the services.
So my packages are organized in the following:
root
root.common
root.serviceA
root.serviceA.<subpackages>
root.serviceB
root.serviceB.<subpackages>
...
root.serviceX
root.serviceX.<subpackages>
In each service I have Program.java where it's tagged with #SpringBootApplication (e.g. root/serviceA/Program.java)
The problem now I'm having is that I have a component in root.common (e.g. root/common/JSONSerializer.java) which needs to be loaded in all the services. I tried tagging the file with #JsonComponent but obviously it doesn't work because it's outside root.service* package.
I managed to get it working by manually adding #Import tag in the main file but that means that for each service I have to manually add #Import({root.common.JSONSerializer.class}) which is tedious and error prone. Is there a way to include this file in the component scanning process?
You can set each Program class by following way:
#SpringBootApplication(scanBasePackages = {"root.serviceA", "root.common"})
REFERENCES
SpringBootApplication documentation
Sorry if this is a duplicate, I looked at several other questions but none seemed to match or provide workable solutions.
Problem
I am writing a Spring Boot (v2.0.2) app, this app exposes a RESTful API which then calls into a WSDL service. I've generated the WSDL classes with Maven/jaxb plugin and everything works from my dev machine. When deployed to the server I get an error that the WSDL service class can not load the underlying WSDL file. The problem is that when the Java classes are generated it is using the full path from my dev machine (snippet from the generated service class)
try {
URL baseUrl;
baseUrl = com.mytest.WSDLService.class.getResource(".");
url = new URL(baseUrl, "/home/users/me/projects/wsdltest/wsdl/MyWSDL.wsdl");
} catch (MalformedURLException e) {
The WSDL file (MyWSDL.wsdl) is in the spring boot JAR file for my application, it is in a subdirectory off root called 'wsdl'
Question Is there a way that I can load this WSDL from the JAR file without having to modify the generated classes?
Ideal Solution I'm hoping to find a solution that doesn't make me modify the generated files (we intend to do this for several services), ideally I'd like a solution which can be done at build time (in the pom.xml?), if that's possible.
Solutions Tried
A post on here suggested using the "wsdlLocation" tag in my pom.xml and provide a explicit path to the WSDL file, e.g. <wsdlLocation>/wsdl/MyWSDL.wsdl</wsdlLocation>
Tried most of the solutions from this thread
Thanks in advance
I think I was able to find a solution thanks to this SO Thread. Evidently the answer depends on the version of the jaxws tool being used in maven (jaxws-maven-plugin). The project (which I inherited) explicitly asked for version 1.12 (which invoked JAX-WS RI 2.1.7-b01-), using this version of the tools I was able to use the '<wsdlLocation>classpath:wsdl/MyWSDL.wsdl</wsdlLocation>' solution in the thread mentioned. Once I noticed that the pom was using an explicit version I removed that the jaxws was updated (using JAX-WS RI 2.2.10) but then the 'classpath' solution stopped working. I switched to the other option mentioned in the thread '<wsdlLocation>/wsdl/MyWSDL.wsdl</wsdlLocation>'
I did a quick test and this seemed to have solved the problem (in both my dev machine and my test site).
Thank you
I'm learning to make Java MVC project using Spring Tool Suite tool.
The path to make new project is:
File->New->SpringLegacyProject->Spring MVC Project.
My question is: which directory I have to use to add additional not-Spring files and where and what do I have to type for Spring files to see them?
For example:
css files - where to put and how to make jsp views see them, will 'link rel="" 'tag be enough?
properties files used to specify database connection or to specify messages for ReloadableResourceBundleMessageSource. In this case, do I have to create bean for this class in root-context.xml?
Thanks.
You should probably use Spring Boot (i.e. use File->New->Spring Starter Project and select Web as a starter. Place your web resources under src/main/resources/static folder. They are picked up automatically from that folder.
You should try an example project: File -> New -> Import Spring Getting Started Content and then pick "Serving Web Content" from the list.
Try some DB getting started content example to get the answer for the second part of your question.
I have found similar Stack Overflow posts for configuring Swagger + SwaggerUI + Jersey, but almost all of these use Spring and I have not been able to find a solution for what I am trying to do.
I have Swagger + Jersey working, and have copied the swagger-ui/dist folder from: https://github.com/swagger-api/swagger-ui to my webapp directory, and have edited swagger-ui/dist/index.html file to point to my swagger.json output. I can properly access Swagger UI at http://localhost:{port}/{base-path}/dist/index.html
However, I do not want to have to copy the pre-build dist files to my webapp directory every time I need to fetch updates. I would like to automate this with Maven (which I am new to as well as Jersey/Swagger), and found this dependency online: https://mvnrepository.com/artifact/org.webjars/swagger-ui/2.0.12
However, I do not understand how to configure the path from my webserver to this webjar dependency.
To recap, I have Swagger UI working on my local machine, but only by manually copying the pre-build files to my webapp directory and would like some way to automate this (I have found solutions using Spring, but I am not using this).
I have worked on implementation of the Entity remote service.
I have created one custom service method in EntityServiceImpl,Created custom service method providing service through InstitutionServiceUtil.
After deploy the portlet, while sending request to service method through from browser window,I am getting below Exception
exception":"java.lang.ClassCastException: com.institutions.model.impl.InstitutionImpl
cannot be cast to com.institutions.model.Institution
Note: If I send the request after restart the server, I didn't get above exception.
How to resolve the above Exception?
I assuming that InstitutionImpl implements the interface Institution. If so, then the root cause of the exception is classloading: Classloader A did load Institution but InstitutionImpl was loaded from a different classloader. Two classes in Java are only equivalent if the fully qualified name and the classloader are the same.
I don't know enough about liferay to tell you how it's class loading works. But to solve the problem, you need to find out if the Institution interface could already be around when you try to load your implementation (maybe from a previous deployment attempt).
While deploying the portlets that throws the class cast exception, do the following:
deploy the application in the liferay/deploy.
shutdown the liferay
move the service jar from the WEB-INF/lib from the portlet to the /lib/ext of the tomcat
remove the temp and work folder from the tomcat
restart the tomcat.
OR ...what worked for me was
change the package name while building the service.xml in the service.xml file
Or if you have already built the service, do these steps
Just delete the 5 packages that are created from the service builder,
i.e
model.impl
service.base
service.http
service.impl
service.persistence
delete the .xml generated in the META-INF folder except for the file ext-spring.xml
delete the XX-service.jar from the docroot/lib folder
delete the service folder in the docroot folder.
change the package name in the service.xml and build the path.