cant enable CORS in spring boot data rest
<p>I need to enable global CORS in my spring boot data rest api to prevent getting the following error whenever i call my api from a browser: 
<a href="http://localhost:8090/posts?user-id=1" rel="nofollow">http://localhost:8090/posts?user-id=1</a>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost" rel="nofollow">http://localhost</a>' is therefore not allowed access.'. </p>

<p>I can type the url into the a browser and receive the correct get response for that resource, yet i cant make the same call from an ajax call in a webpage. </p>

<p>Any ideas what im missing?</p>

<p>My code and config is below:</p>

<pre><code>@SpringBootApplication
@EnableAutoConfiguration
@EnableJpaRepositories
@EnableWebMvc
public class Application  {

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);

}

@Bean
public WebMvcConfigurer corsConfigurer() {

    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**");
        }
    };
}

@Bean
public CommandLineRunner demo(UserRepository userRepository, PostRepository postRepository,
                              CommentRepository commentRepository, EventRepository eventRepository, VenueRepository venueRepository) {
    return (args) -&gt; {

        User user = new User("fsdsdfsd","sdsdsds","121212");
        userRepository.save(user);

        Venue venue = new Venue("dsaesrdfddgd","aerttyhyyty","yyyyyyyyyyyyyy");
        venueRepository.save(venue);

        Event event = new Event("dsaesrdfddgd","aerttyhyyty","yyyyyyyyyyyyyy",venue,user);
        eventRepository.save(event);

        Post post = new Post("some posts are funny. Some are not.",user, event);
        postRepository.save(post);

        Comment comment = new Comment("commmentntnrnejfnerfdgdfgdfdt", user, post);
        commentRepository.save(comment);
    };
}
</code></pre>

<p>}</p>

<pre><code>@RepositoryRestResource
public interface PostRepository extends PagingAndSortingRepository&lt;Post, Long&gt; {


Page&lt;Post&gt; readBydeletedIsFalseOrderByCreated(Pageable pageRequest);

@CrossOrigin
Post readByIdAndDeletedIsFalse(Long postId);
</code></pre>

<p>}</p>

<pre><code>buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'project'
    version = '0.1.0'
}

war {
    baseName = 'project'
    version = '0.1.0'
}


repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("com.h2database:h2")
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}
</code></pre>