Skip to content

Commit c41758d

Browse files
committed
调整包命名
1 parent 41a3e91 commit c41758d

File tree

22 files changed

+586
-0
lines changed

22 files changed

+586
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.souvc.springboot</groupId>
6+
<artifactId>springboot-sample-importresource</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>springboot-sample-importresource</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.4.3.RELEASE</version>
17+
</parent>
18+
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
</properties>
23+
24+
<dependencies>
25+
26+
<dependency>
27+
<groupId>junit</groupId>
28+
<artifactId>junit</artifactId>
29+
<version>3.8.1</version>
30+
<scope>test</scope>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
38+
39+
</dependencies>
40+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.souvc.springboot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.ResponseBody;
10+
11+
/**
12+
* Hello world!
13+
*
14+
*/
15+
/*@Controller
16+
@EnableAutoConfiguration
17+
@ComponentScan*/
18+
@SpringBootApplication
19+
public class App
20+
{
21+
@RequestMapping("/")
22+
@ResponseBody
23+
String home() {
24+
return "Hello World!";
25+
}
26+
27+
public static void main(String[] args) throws Exception {
28+
SpringApplication.run(App.class, args);
29+
}
30+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.souvc.springboot.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.context.annotation.ImportResource;
5+
6+
/**
7+
* classpath路径:locations={"classpath:application-bean1.xml","classpath:application-bean2.xml"}
8+
* file路径: locations = {"file:d:/test/application-bean1.xml"};
9+
*/
10+
11+
@Configuration
12+
@ImportResource(locations={"classpath:application-bean.xml"})
13+
public class ConfigClass {
14+
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.souvc.springboot.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.context.annotation.ImportResource;
5+
6+
/**
7+
* classpath路径:locations={"classpath:application-bean1.xml","classpath:application-bean2.xml"}
8+
* file路径: locations = {"file:d:/test/application-bean1.xml"};
9+
*/
10+
@Configuration
11+
@ImportResource(locations={"file:d://application-bean1.xml"})
12+
public class ConfigClass2 {
13+
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.souvc.springboot.service;
2+
3+
4+
import org.springframework.stereotype.Service;
5+
6+
@Service
7+
public class HelloService {
8+
9+
/**
10+
* 启动的时候观察控制台是否打印此信息;
11+
*/
12+
public HelloService() {
13+
System.out.println("HelloService.HelloService()");
14+
System.out.println("org.souvc.springboot.service.HelloService.HelloService()");
15+
System.out.println("HelloService.HelloService()");
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.souvc.springboot.service;
2+
3+
import org.springframework.stereotype.Service;
4+
5+
6+
@Service
7+
public class HelloService2 {
8+
9+
/**
10+
* 启动的时候观察控制台是否打印此信息;
11+
*/
12+
public HelloService2() {
13+
System.out.println("HelloService2.HelloService2()");
14+
System.out.println("HelloService2.HelloService2()");
15+
System.out.println("HelloService2.HelloService2()");
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
5+
6+
<!-- 注入spring boot无法扫描到的bean. -->
7+
<bean id="helloService" class="com.souvc.springboot.service.HelloService"></bean>
8+
9+
</beans>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.souvc.springboot;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

spring-boot-sample-kaptcha/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.souvc</groupId>
7+
<artifactId>springboot-sample-kaptcha</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>springboot-sample-kaptcha</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.2.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
29+
<!--SpringBoot依赖 -->
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-web</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-test</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<!-- 验证码 -->
42+
<dependency>
43+
<groupId>com.github.axet</groupId>
44+
<artifactId>kaptcha</artifactId>
45+
<version>0.0.9</version>
46+
</dependency>
47+
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-maven-plugin</artifactId>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
59+
60+
</project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.souvc;
2+
3+
import java.awt.image.BufferedImage;
4+
5+
import javax.imageio.ImageIO;
6+
import javax.servlet.ServletOutputStream;
7+
import javax.servlet.http.HttpServletRequest;
8+
import javax.servlet.http.HttpServletResponse;
9+
import javax.servlet.http.HttpSession;
10+
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.stereotype.Controller;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.servlet.ModelAndView;
15+
16+
import com.google.code.kaptcha.Constants;
17+
import com.google.code.kaptcha.Producer;
18+
19+
@Controller
20+
@RequestMapping("/kaptcha/*")
21+
public class CaptchaController {
22+
23+
@Autowired
24+
private Producer captchaProducer;
25+
26+
@RequestMapping
27+
public ModelAndView getKaptchaImage(HttpServletRequest request, HttpServletResponse response) throws Exception {
28+
HttpSession session = request.getSession();
29+
String code = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY);
30+
System.out.println("******************验证码是: " + code + "******************");
31+
32+
response.setDateHeader("Expires", 0);
33+
34+
// Set standard HTTP/1.1 no-cache headers.
35+
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
36+
37+
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
38+
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
39+
40+
// Set standard HTTP/1.0 no-cache header.
41+
response.setHeader("Pragma", "no-cache");
42+
43+
// return a jpeg
44+
response.setContentType("image/jpeg");
45+
46+
// create the text for the image
47+
String capText = captchaProducer.createText();
48+
49+
// store the text in the session
50+
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
51+
52+
// create the image with the text
53+
BufferedImage bi = captchaProducer.createImage(capText);
54+
ServletOutputStream out = response.getOutputStream();
55+
56+
// write the data out
57+
ImageIO.write(bi, "jpg", out);
58+
try {
59+
out.flush();
60+
} finally {
61+
out.close();
62+
}
63+
return null;
64+
}
65+
66+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.souvc;
2+
3+
import com.google.code.kaptcha.impl.DefaultKaptcha;
4+
import com.google.code.kaptcha.util.Config;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
import java.util.Properties;
11+
12+
@SpringBootApplication
13+
@Configuration
14+
public class SpringbootSampleKaptchaApplication {
15+
16+
@Bean
17+
public DefaultKaptcha captchaProducer(){
18+
DefaultKaptcha captchaProducer =new DefaultKaptcha();
19+
Properties properties =new Properties();
20+
properties.setProperty("kaptcha.border","yes");
21+
properties.setProperty("kaptcha.border.color","105,179,90");
22+
properties.setProperty("kaptcha.textproducer.font.color","blue");
23+
properties.setProperty("kaptcha.image.width","125");
24+
properties.setProperty("kaptcha.image.height","45");
25+
properties.setProperty("kaptcha.textproducer.font.size","45");
26+
properties.setProperty("kaptcha.session.key","code");
27+
properties.setProperty("kaptcha.textproducer.char.length","4");
28+
properties.setProperty("kaptcha.textproducer.font.names","宋体,楷体,微软雅黑");
29+
Config config=new Config(properties);
30+
captchaProducer.setConfig(config);
31+
return captchaProducer;
32+
}
33+
34+
35+
public static void main(String[] args) {
36+
SpringApplication.run(SpringbootSampleKaptchaApplication.class, args);
37+
}
38+
}

spring-boot-sample-kaptcha/src/main/resources/application.properties

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.souvc;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class SpringbootSampleKaptchaApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)