@CrossOrigin annotation stops compilation in IntelliJ

When I compile any class that contains the Spring @org.springframework.web.bind.annotation.CrossOrigin annotation using maven from the command line, it compiles just fine. But when I try to compile the same code using IntelliJ Idea 15, I get this strange error:

 [ERROR] /Users/gregederer/devewx2/geoengine/src/main/java/geoengine/controller/rest/TimeSeriesController.java:[34,1] annotation org.springframework.web.bind.annotation.CrossOrigin is missing value for the attribute <clinit> 

This may be due to https://community.oracle.com/message/4827054 . But this problem has never been resolved.

Any suggestions?

+5
source share
5 answers

You can exclude the error from being included in the scan through IntelliJ by right-clicking it, and then it should compile.

Edit: a JDK update appears - this is a suitable fix, my suggestion was intended to quickly work around the problem and was rather a fix for bandids, since the validation error should not have affected anything. See Nikki's answer for an explanation.

-2
source

Try using JDK 1.7.0_80. I ran into this problem using JDK 1.7.0_79. It only worked on 1.7.0_80.

+12
source

I have the same problem ... Exclusion from the check did not help in my case. When I compile it from cmd with mvn everything works fine, but from intellij it is not. My intellij settings forced me to use java jdk 1.7 (necessary for the project). When I set it to 1.8, I have no problem. I assume this is a bug in javac 7 (see here ).

I ran into a problem (known and resolved in 1.8) with javac lack of annotations with static end fields requiring complex initialization. The malfunction manifests itself in the last 1.7

+1
source

I had the same problem when deploying my application to travis ci which installed oracle jdk 1.7.0_76. I forcefully updated jdk7 and then upgraded to jdk 1.7.0_80. @CrossOrigin annotations did not complain after that.

0
source

Today, faced with this problem, I also browsed the Internet and could not find a direct answer. In my case, using a higher version of Java was not possible, because the project had to be deployed in JDK 6. However, in the end I found a solution, hope this helps someone else.

The key moment Java is compatible with feedback .

This is the answer:). You can use a higher version of the JDK , such as 1.7 or 1.8 , to compile your project and use the -target option to cross-compile to a lower version.

-target version

Generate class files for the specified version of the virtual machine. Class files will run on the specified target and in later versions, but not on earlier versions of the virtual machine. Acceptable goals: 1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6) and 1.7 (also 7).

The default value for -target depends on the value of -source:

If -source is not specified, the value of -target is 1.7

If -source is 1.2, then -target is 1.4

If -source is 1.3, then -target is 1.4

If -source is 1.5, then -target is 1.7

If -source is 1.6, then -target is 1.7

For all other -source values, the -target value is the -source value.

Link: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

I used Maven, so I just had to change the <java.version> property in the POM , and that’s it. I still used Java 8, with the latest Maven, but maven cross-compiled JDK6.

0
source

Source: https://habr.com/ru/post/1236846/


All Articles