Neither Spring Boot Actuator + Hal-Browser nor DevTools working - spring

Updated: Attached pom.xml and application.property and some more error / warning msgs.
Hi I am very new to Spring Boot and just taking some classes on Udemy for it.
While following through a class, I create a starter project via spring.io and added actuator and Hal browser dependencies including Dev tools.
Just ran my app and tried to go to localhost:8080/application & /browser as well but I get 404.
What am I doing wrong?
I wrote a simple bean which returns a hard coded value and then print that, I changed the value to test Dev tools and it didn’t restart the resource , I had to kill and restart the app to reflect the new changes ..
How can I check what the issue ?
I can provide console grab if needed.
Please help.
Update: I don't know the significance of the following so putting it in here.
in the XML editor hal is red underlined with the following msg on hover:
The managed version is 3.0.5.RELEASE The artifact is managed in org.springframework.data:spring-data-releasetrain:Kay-SR5
in the XML editor devtools is red underlined with the following msg on hover:
The managed version is 2.0.0.RELEASE The artifact is managed in org.springframework.boot:spring-boot-dependencies:2.0.0.RELEASE
pom.xml:
<?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.myoxigen.training.springboot</groupId>
<artifactId>library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>library</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties file:
logging.level.org.springframework = DEBUG
management.security.enabled=false

Note: This answer is based on Spring Boot 2 (paths and properties have changed from version 1).
Your pom.xml looks fine to me. To get the "HAL Browser" to work with actuator you should have starters: web, actuator, and Rest Repositories HAL Browser. I recommend Spring Initializr as a nice way to construct an initial valid project structure.
The default path for the actuator is /actuator. Health, for example, is at /actuator/health.
To view the actuator endpoints in the HAL Browser, go to /browser/index.html#/actuator.
You can change the actuator path in application.properties by setting the following.
management.endpoints.web.base-path=/actuator
To run your server, use the following console command:
./mvnw clean spring-boot:run
If you have DevTools in your project, then changes to files in your classpath will restart the server. See my further comments on how to take advantage of DevTools here.
Here's the relevant documentation on a single page for easy searching:
https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle

Add this Dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.3.5.RELEASE</version>
</dependency>`enter code here`
And then go to link:
http://localhost:8080/browser/index.html#

Spring Boot 2.2 apps should use spring-data-rest-hal-explorer rather than spring-data-rest-hal-browser
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>

For enabling actuator, add this into the property file (application.properties)
management.endpoints.web.exposure.include=*
Restart the Spring boot application and access the actuator endpoints using:
http://localhost:8080/actuator/
the health of the application can also be monitored using:
http://localhost:8080/actuator/health
dependency required:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Ain't you were studying a course by "in28minutes"? =) Anyway when I studied on a Spring Boot for Beginners in 10 Steps course, I faced the same issue with accessing http://localhost:8080/application.
For http://localhost:8080/browser I got a plain json:
{"cause":null,"message":"Fragment must not be empty"}
In pom.xml I had the same dependencies as you outlined in question.
Some googling brought me to this article. In section named "II. Hal Browser" you can see a screenshot, where in browser a link is http://localhost:8080/browser/index.html#. If use this link, then Hal Browser should magically appear.
So /index.html# was the only puzzle piece you missed.
Note: above approach worked with Spring Boot version 2.1.7
EDIT: despite the fact that Hal Browser itself works with above approach, it still doesn't show actuator endpoints. And DevTools also ain't working for me.

Related

How to run Swagger 3 on Spring Boot 3

Using a fresh Spring Initialzr with Java17 and Spring Boot 3.0.0, and an extra addition to the pom.xml for Springfox Swagger 3, I can't for the life of me get Swagger pages to work. Instead, I get the whitelabel error page with 404.
Pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</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>
</plugins>
</build>
</project>
The standard Swagger URLs as defined in this Github Issues page aren't working for the above pom.xml project.
I had given up and went to use Spring Boot 2.7 after posting the question. But, after seeing Dmitriy's answer though, I checked Springdoc one last time and found that Springdoc v2 does support Spring Boot 3.
Essentially, one has to place the following in their pom:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
Then one can access the Swagger page using the following URL: http://localhost:8080/swagger-ui.html (Don't forget to add context path if you need it). For some reason, when opening, it redirects to http://localhost:8080/swagger-ui/index.html although going for that initially returned 404...
in addition to adding springdoc-openapi-starter-webmvc-ui (v2.0.2 for me) as indicated in the accepted answer, I also needed to remove org.springdoc:springdoc-openapi-ui:1.6.13 .
It was there because I had tried it before. If present, there's still a non Jakarta reference that Spring tries to resolve (and fails to do so).
I also needed to add this dependency, otherwise I would have a nasty message at startup (version is resolved by Spring Boot BOM) :
implementation group: 'org.hibernate.validator', name: 'hibernate-validator'
Lastest
springfox-boot-starter version 3.0.0
and
springdoc-openapi-ui 1.6.13
seems not to support spring-boot 3.
We need to wait until the new version adopts jakarta.servlet package
Springdoc is working with Spring boot 3.0.1
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
Default URL: http://localhost:8080/swagger-ui/index.html
For Gradle you can add this:
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.0'
I agreed with #Ahmed Tawfik because I also faced the same. But today I tried that same approach with the new version of "springdoc-openapi-starter-webmvc-ui" dependency and Spring Boot 3.0.2-SNAPSHOT.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
because the previous one "springdoc-openapi-ui" is changed to the above one.
Also, include below the path to the security config for swagger UI.
"/v3/api-docs/**","/swagger-ui/**"
For my project,
#Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.cors(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)
.exceptionHandling(exceptionHandlingConfigurer -> exceptionHandlingConfigurer.authenticationEntryPoint(unauthorizedHandler))
.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> {
try {
authorizationManagerRequestMatcherRegistry
.requestMatchers(HttpMethod.POST, POST_AUTH_WHITELIST).permitAll()
.requestMatchers(HttpMethod.GET, GET_AUTH_WHITELIST).permitAll()
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**").permitAll()
.anyRequest()
.authenticated()
.and()
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
} catch (Exception e) {
throw new ResourceNotFoundException(e.getMessage());
}
}
)
.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable).addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.authenticationProvider(daoAuthenticationProvider()).build();
}
The swagger UI link will be:
http://server:port/context-path/swagger-ui.html
Please adjust the server, port, and context-path regarding your personal changes.
All the above steps are working fine with my project. I don't need extra configuration.
Also, you can add the custom path (Optional):
springdoc.swagger-ui.path=/swagger-ui.html
Here is the Official Documentation of OpenApi 3 and Spring Boot : https://springdoc.org/v2/#features
In the above documentation, you can explore additional configurations and other things also.
Happy Learning! ✌️
Use Open API instead swagger for Spring v3.0. Follow this document Open API Docs
Following dependencies working fine to me.
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.app</groupId>
<artifactId>hello-world</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>

Spring boot SSO with Oauth2 and Spring-boot-starter-parent version 2+

I got a good and simple SSO sample project from here
Currently the sample works as below.
Start app1, app2, sso-server.
Load http://localhost:8082/app1 It will redirect to login page of
http://localhost:8080/sso-server
username: user, password: password
On successful login, it will redirect back to
http://localhost:8082/app1 The page will show "Welcome to app1, user"
Now on loading http://localhost:8083/app2 The page will show "Welcome
to app2, user" since we have already logged in.
Now my issue is the sample uses spring-boot-starter-parent version 1.5.9.RELEASE
The sample uses spring-cloud dependency also. I read like spring-cloud will not support spring-boot-starter-parent version 2 or above.
So I tried to remove spring cloud dependency from app1 and I could start the application after a tough try. My new pom is as below.
<?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.shekhargulati</groupId>
<artifactId>app1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>app1</name>
<description>App1</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
</dependencies>
Now on loading app1, it will show sso login window. But after successfull login, it will throw 404 error.
And if I do the same changes in sso-server application, the authorization will not work. Authorization API wil lthrow 404.
Please help me to fix this.
My need is, make this application work as earlier with spring boot starter parent version 2+.
Here is the link for the code in github which is forked from the link which is provided in the above question which is providing all the feature you have expected using Spring-Boot 2.X version.
In the above code I have moved your code from Spring boot version 1.5.9.RELEASE to 2.1.3.RELEASE and Spring Cloud version from Edgware.SR1 to Finchley.SR1

SpringBoot app shows Whitelabel Error Page while serving JSP from JAR

I am exploring how JSPs can be served from JAR file. I'm using SpringBoot 1.5.10.RELEASE
I referred this & this examples and was able to create spring boot app which
includes JSPs at location src/main/resources/META-INF/resources/WEB-INF/jsp/
view resolver has prefix as /WEB-INF/jsp/ and suffix as .jsp
Strange thing is when I ran project as springboot app or Java App, I was able to hit the controller and got desired JSP file as response. After that I thought of packaging the app and then running it from JAR.
$ mvn package
$ java -jar target/springboot-web-jar-demo-0.0.1-SNAPSHOT.jar
Spring boot app comes up, when I hit the same URL pattern, control comes in the mapped method but after that...
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Feb 28 21:01:09 IST 2018
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/index.jsp
My problem/question...
Is there any major difference between the springboot app runs in IDE and when it runs as JARs, which can even cause 404?
Does spring boot 1.5.10.RELEASE support serving JSPs from JAR? (if yes then what I'm missing here, if no then where it is mentioned) - stackoverflow-link
I have tried searching proper solution or answer to my problem but didn't get any. Hence posting the question here please help.
Note:
Please don't provide solution for WAR packaging
I know JSP are not best choice nowadays, I'm just learning
I'm aware that I can look for alternatives like thymeleaf, freemarker and velocity
I don't want to downgrade the SpringBoot version
I've also tried specifying <scope> of jasper & JSTL to provided and compile but no luck
pom.xml
<?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.atuldwivedi.learn.springboot</groupId>
<artifactId>springboot-web-jar-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springboot-web-jar-demo</name>
<description>Learn how to serve JSP from JAR</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath />
</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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
For you spring boot recognize their jsps, you debt create a webapp directory in src.main like this:
src/main/webapp/WEB-INF/jsp
and not like:
src/main/resources/META-INF/resources/WEB-INF/jsp
for dispatcherServelet recognize their jsps, you create a webapp directory in src.main like this:
src/main/webapp/WEB-INF/jsp
and also autoconfigure your application in application.properties
spring.mvc.view.prefix:/WEB-INF/jsp
spring.mvc.view.suffix:.jsp`
JSPs are not supported when using an executable jar.

Spring Boot project in IntelliJ IDEA stops working after reboot

This is probably a newbie question, but I am not able to sort things out.
I've created a Spring Boot JAR-based Maven project using the Spring Initializr interface in IntelliJ IDEA. Its dependencies on Web and JDBC; an embedded instance of Tomcat is used to run the project.
I also have a couple of other Maven dependencies I add without problems from the relevant dialog; I also manually add the Apache Phoenix thin client JAR, that includes a copy of Logback (I am not able to get their Maven repository to work, but I don't think this is relevant to this question).
I am able to run the project flawlessly; after a system reboot (I am on Windows), a cascade of errors follows. First and foremost an exception signaling a conflict between Logback comes:
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from [...]). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory.
I would not like to alter the Phoenix client JAR; I am able to follow the instructions to replace the Spring dependency on Logback with another logger (log4j2 for example), but then the embedded Tomcat fails to create the container.
To get back to work, I have to recreate the project from scratch.
Could you please point me in the right direction to pinpoint the actual problem? Thank you.
Post scriptum: I am attaching the content of my pom.xml, apart from some potentially identifying information.
<?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>[RETRACTED]</groupId>
<artifactId>[RETRACTED]</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>[RETRACTED]</name>
<description>[RETRACTED]</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>
</plugins>
</build>
</project>
Firstly, rather than adding the apache phoenix client (or any other dependencies) manually you should add them to your maven pom.xml, so maven resolves the dependency at build time. If your project has dependencies which maven is failing to resolve this is a separate issue which you need to resolve, but adding them manually is bad practice for a number of reasons.
Once you have added the phoenix client as a dependency, you need to explicitly exclude slf4j-log4j12 and log4j as part of the dependency declaration. The XML should look something like this:
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.13.1-HBase-1.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
The reason these need excluded is that they are conflicting with the versions bundled in the spring-boot project
Hopefully this will sort your problem.

Using #CrossOrigin in Spring Boot

I'm using latest Spring Boot (1.2.7.RELEASE). I would like to use the #CrossOrigin annotation from the package org.springframework.web.bind.annotation as described in CORS Support section in Spring docs.
I'd think I already have all the necessary dependencies (via Spring Boot defaults), but this is confusing: CrossOrigin is not found, even though stuff like RestController from the same package works!
Error:(8, 47) java: cannot find symbol
symbol: class CrossOrigin
location: package org.springframework.web.bind.annotation
What's going on? Has CrossOrigin been removed from later versions of Spring-MVC, or am I missing some dependency?
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Alright, looks like the latest Spring Boot release, 1.2.7.RELEASE at the moment, is too old to have a version of Spring MVC with CrossOrigin. (Spring Boot 1.2.7 uses Spring version 4.1.8).
I updated to latest Spring Boot 1.3 release candidate (1.3.0.RC1) and it works:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RC1</version>
</parent>
Also needed to specify spring-milestones repository in pom.xml to be able to use the non-release version.
<repositories>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
Update: override Spring version
As Stéphane Nicoll pointed out, a simpler way to get Spring 4.2.2 classes (such as CrossOrigin) into use is this:
<properties>
<!-- ... -->
<spring.version>4.2.2.RELEASE</spring.version>
</properties>
#CrossOrigin annotation is used to provide support for cross domains,
ie nothing but from different domains also we can access that service
by default it is true.
we can access the services from cross domains also.

Resources