SpringBoot Setup
POM.XML
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- tag::actuator[] --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- end::actuator[] --> <!-- tag::tests[] --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- end::tests[] --> </dependencies> <properties> <java.version>1.7</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
SPRING APPLICATION MAIN CLASS
@SpringBootApplication @EnableAutoConfiguration @ComponentScan(basePackages="com.bellinfo.springboot") public class BellInfoApplication { public static void main( String[] args ) { SpringApplication.run(BellInfoApplication.class, args); System.out.println( "Hello World!" ); } }
REST CONTROLLER
import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping(value="/student") public class StudentController { @RequestMapping(method=RequestMethod.GET, consumes=MediaType.APPLICATION_JSON_VALUE, produces=MediaType.APPLICATION_JSON_VALUE) public HelloStudent Hello(){ HelloStudent hs = new HelloStudent(); hs.setName("Siva"); hs.setSalary("10000"); return hs; } }
References :
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/
https://spring.io/guides/gs/spring-boot/
Logback
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-access</artifactId> <version>1.1.3</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.3</version> </dependency>
LOG4J
<configuration> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>foo.log</file> <encoder> <pattern>%date %level [%thread] %logger{10} [%file : %line] %msg%n</pattern> </encoder> </appender> <logger name="org.springframework" level="error"/> <logger name="com.bellinfo.helloworld" level="info"/> <root level="warn"> <appender-ref ref="FILE" /> </root> </configuration>