-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring and Spring boot support #22
Comments
Hi arturhg. Thanks for the report! Quick answer. YES. It is possible to use Manifold with Spring. I've generated a demo Spring app using spring initializr, added Manifold dependency, and a simple use-case. I can reproduce an exception (attached to this post) with a call to Update:Good news! After further inspection the exception from Spring is actually just a scary warning logged to the console, it does not interrupt normal execution, therefore nothing to be concerned about. In any case, you can use the workaround documented in this post to avoid the warning. Based on the stack trace it appears Spring scans the classpath of the application's URLClassLoader and assumes all the URLs are files. Unfortunately, they may not all be files because Manifold adds a special URL to the class loader with the "manifoldclass" protocol. In my view Spring should simply skip URLs that are not files instead of allowing the exception to fall through -- there is no harm in skipping a URL it can't handle. Perhaps I'll add a pull request to fix this. Fortunately, you can avoid this problem in a number of different ways, depending on your needs. The easiest fix is to simply add the @NoBootstrap annotation to the main class e.g., @SpringBootApplication
@NoBootstrap
public class DemoApplication { This tell Manifold not to generate a class initializer to bootstrap Manifold at runtime. Instead another class that has the initializer will do it. However, if your main class requires runtime features you'll have to bootstrap manually before the runtime is needed. Doing this involves adding a simple call wherever you need it: Bootstrap.init(); Features that require Manifold runtime include:
Let me know if this helps. There are other ways to work around the exception. I'll document them and push the Spring sample app to github for future reference. Let me know if you have additional questions or issues. Thanks again for the report! Scott Exception: (note this exception is merely logged, it does not stop normal execution of your application)
|
Amazing answer, rsmckinney! |
Update I logged https://jira.spring.io/browse/SPR-17417, which is now fixed :) |
Thank you so much, rsmckinney! |
It works! Thanks a lot. |
Hi @rsmckinney! You promised once...
... So where can one find this aforementioned template? =) |
Hi @marksto. Lol, that was a while ago. As I recall after the bug in Spring was fixed to eliminate the warning message I realized there wasn't anything special to do -- you can simply add Manifold dependencies to existing Spring-based projects. Here is the POM file from the app used: <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>systems.manifold</groupId>
<artifactId>manifold-all</artifactId>
<version>0.59-alpha</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<encoding>UTF-8</encoding>
<compilerArgs>
<!--Add the Manifold plugin, with string templates and checked exception suppression enabled-->
<arg>-Xplugin:Manifold strings exceptions</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project> Let me know if you're having trouble using Manifold with a Spring app. Cheers. |
I am building a jar from spring boot application that uses manifold for dynamic json 2 java. and get the following error only for jar execution but runs fine on IntelliJ. |
Is it possible to use Manifold with Spring and Spring Boot projects?
I tried Manifold with Spring Boot 1.x and it crashed with different exceptions each time.
Probably should try again and post trace here.
Thank you.
The text was updated successfully, but these errors were encountered: