Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Spring with Gradle cannot find symbol @Controller and @ResponseBody

Greetings, I've been following along with the Spring Basics course. How can I check dependencies again. I'm getting "cannot find symbol @Controller" and cannot find symbol for @ResponseBody. I'm at the section "Create a Controller to Handle HTTP Requests". Thank you.

4 Answers

Hey Miltion, I think I might see the problem. in your import statements be sure to include

import org.springframework.stereotype.Controller;

That should help find the @Controller annotation.

Also, to import the response body try:

import org.springframework.web.bind.annotation.ResponseBody;

These two should work, if they do not let me know.

Hey Milton, can you post your code and your gradle build file, I'll check and see if I can find what's missing.

Hi Rob, **********************************************here is my build file: ********************************************** group 'com.teamtreehouse' version '1.0-SNAPSHOT'

buildscript{ repositories{ mavenCentral() } dependencies{ classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE' } }

apply plugin: 'java' apply plugin: 'spring-boot'

sourceCompatibility = 1.5

repositories { mavenCentral() }

dependencies { compile 'org.springframework.boot:spring-boot-starter-web:1.2.6.RELEASE' } ***********************************here is my GifController.java ********************************************** package com.teamtreehouse.giflib.controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller public class GifController { @RequestMapping("/") @ResponseBody public String listGifs(){ return "List of all the GIFs!"; } } **********************************************And here is my AppConfig.java file ********************************************** package com.teamtreehouse.giflib;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan;

@EnableAutoConfiguration @ComponentScan public class AppConfig { public static void main(String[] args){ SpringApplication.run(AppConfig.class, args); } }

That worked Rob! Thank you.