[i][b]入门demo
[/b][/i]
[i][b]application-context.xml文件:[/b][/i]
[i][b]pom.xml 文件:[/b][/i]
[/b][/i]
1. eclispe 创建一个基本的maven项目
2. 配置pom.xml 引入spring boot所需要的jar包 见下文
3. 新建pojo controller
4. 创建Application.java 通过main方法启动项目
@SpringBootApplication
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
@Configuration
@ImportResource("classpath:/application-context.xml")
class XmlImportConfiguration {
}
[i][b]application-context.xml文件:[/b][/i]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd"
default-autowire="byName" default-init-method="init">
<context:component-scan base-package="com.mysite.*" />
<context:property-placeholder
ignore-resource-not-found="false" order="1"
ignore-unresolvable="true"
system-properties-mode="ENVIRONMENT"
location="classpath:application.properties"/>
</beans>
[i][b]pom.xml 文件:[/b][/i]
<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.leotest.lmx</groupId>
<artifactId>mysite</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency> -->
<!-- Package as an executable JAR -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>