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 Basics Creating Controllers and Views Create a Controller to Handle HTTP Requests

One intellij I get 2 warnings. One says the GifController class isn't used and the other is listGifs() is never used.

The Whitelabel Error Page still apears as well

My build.gradle file:

plugins { id 'java' id 'idea' id 'eclipse' id 'org.springframework.boot' version '2.4.3' }

group 'com.teamtreehouse' version '1.0-SNAPSHOT'

repositories { mavenCentral() }

dependencies { //layout='group id:artifact id:version' compile 'org.springframework.boot:spring-boot-starter-web:2.4.3' }

test { useJUnitPlatform() }

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//allows spring to be auto configured @ComponentScan//Scans for controllers public class AppConfig { public static void main(String[] args) { SpringApplication.run(AppConfig.class, args);//allows us to run this app } }

My GifController.java file:

package controller;

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;

@Controller//Saying that this is a controller public class GifController { @RequestMapping("/")//saying to execute this method when homepage is requested @ResponseBody//indicates string returned is to be used as a response without any further processing public String listGifs(){ return "List of all the gifs"; } }