Skip to content

Commit e107dd8

Browse files
committed
fix spring and springmvc auto scan annotation collection
1 parent 920e9d0 commit e107dd8

File tree

12 files changed

+223
-123
lines changed

12 files changed

+223
-123
lines changed

pom.xml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
<dependencies>
15+
<!--junit相关包-->
1516
<dependency>
1617
<groupId>junit</groupId>
1718
<artifactId>junit</artifactId>
@@ -23,12 +24,8 @@
2324
<artifactId>hamcrest-core</artifactId>
2425
<version>1.3</version>
2526
</dependency>
26-
<dependency>
27-
<groupId>commons-collections</groupId>
28-
<artifactId>commons-collections</artifactId>
29-
<version>3.2.1</version>
30-
</dependency>
3127

28+
<!--shiro相关包-->
3229
<dependency>
3330
<groupId>org.apache.shiro</groupId>
3431
<artifactId>shiro-core</artifactId>
@@ -55,7 +52,7 @@
5552
<version>1.2.4</version>
5653
</dependency>
5754

58-
55+
<!--mysql数据库连接-->
5956
<dependency>
6057
<groupId>mysql</groupId>
6158
<artifactId>mysql-connector-java</artifactId>
@@ -74,6 +71,8 @@
7471
<artifactId>aspectjweaver</artifactId>
7572
<version>1.8.8</version>
7673
</dependency>
74+
75+
<!--spring相关包-->
7776
<dependency>
7877
<groupId>org.springframework</groupId>
7978
<artifactId>spring-test</artifactId>
@@ -85,26 +84,25 @@
8584
<artifactId>spring-context-support</artifactId>
8685
<version>4.2.4.RELEASE</version>
8786
</dependency>
88-
8987
<dependency>
9088
<groupId>org.springframework</groupId>
9189
<artifactId>spring-jdbc</artifactId>
9290
<version>4.2.4.RELEASE</version>
9391
</dependency>
94-
9592
<dependency>
9693
<groupId>org.springframework</groupId>
9794
<artifactId>spring-tx</artifactId>
9895
<version>4.2.4.RELEASE</version>
9996
</dependency>
10097

98+
<!--springmvc-->
10199
<dependency>
102100
<groupId>org.springframework</groupId>
103101
<artifactId>spring-webmvc</artifactId>
104102
<version>4.2.4.RELEASE</version>
105103
</dependency>
106104

107-
105+
<!--servlet,jsp,jstl-->
108106
<dependency>
109107
<groupId>javax.servlet</groupId>
110108
<artifactId>javax.servlet-api</artifactId>
@@ -123,7 +121,7 @@
123121
</dependency>
124122

125123

126-
<!--mybatis-->
124+
<!--mybatis相关包-->
127125
<dependency>
128126
<groupId>org.mybatis</groupId>
129127
<artifactId>mybatis-spring</artifactId>
@@ -164,7 +162,6 @@
164162
<artifactId>slf4j-log4j12</artifactId>
165163
<version>1.7.14</version>
166164
</dependency>
167-
168165
<dependency>
169166
<groupId>ognl</groupId>
170167
<artifactId>ognl</artifactId>
@@ -176,6 +173,7 @@
176173
<version>3.20.0-GA</version>
177174
</dependency>
178175

176+
<!--数据源-->
179177
<dependency>
180178
<groupId>org.apache.commons</groupId>
181179
<artifactId>commons-pool2</artifactId>
@@ -186,19 +184,23 @@
186184
<artifactId>commons-dbcp2</artifactId>
187185
<version>2.1</version>
188186
</dependency>
187+
189188
<!--json parser-->
190189
<dependency>
191190
<groupId>com.google.code.gson</groupId>
192191
<artifactId>gson</artifactId>
193192
<version>2.6</version>
194193
</dependency>
194+
195195
<!--file upload-->
196196
<dependency>
197197
<groupId>commons-fileupload</groupId>
198198
<artifactId>commons-fileupload</artifactId>
199199
<version>1.3.1</version>
200200
</dependency>
201201

202+
203+
202204
</dependencies>
203205

204206
<build>

src/main/java/com/giit/www/college/controller/ClazzController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* Created by c0de8ug on 16-2-11.
1515
*/
1616
@Controller
17-
1817
@RequestMapping("clazz.do")
1918
public class ClazzController {
2019

src/main/java/com/giit/www/college/controller/CourseController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* Created by c0de8ug on 16-2-12.
1414
*/
1515
@Controller
16-
1716
@RequestMapping("course.do")
1817
public class CourseController {
1918
@Resource(name = "courseBizImpl")

src/main/java/com/giit/www/college/controller/StudentController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public String add(Model m, MultipartFile pic, Student student) throws IOExceptio
5353

5454
@RequiresRoles("admin")
5555
@RequestMapping("delete")
56-
5756
public String delete(Model m, int studentId) {
5857
studentBiz.delete(studentId);
5958
return "redirect:/student.do/student.view";

src/main/java/com/giit/www/system/controller/LoginController.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,11 @@
2020
* Created by c0de8ug on 16-2-14.
2121
*/
2222
@Controller
23-
//@RequestMapping("login.do")
2423
public class LoginController {
2524

2625
@Resource(name = "userBizImpl")
2726
UserBiz userBiz;
2827

29-
// @Resource(name = "accountBizImpl")
30-
// private AccountBiz accountBiz;
31-
//
32-
// @RequestMapping("login")
33-
// public String login(HttpSession session, String username, String password) {
34-
// User user;
35-
// user = accountBiz.findByIdAndPassword(username, password);
36-
// if (user != null) {
37-
// session.setAttribute("username", username);
38-
//
39-
// //TODO 为了测试写死
40-
// String temp = "0";
41-
// switch (temp) {
42-
// case "0":
43-
// return "/admin/main";
44-
// case "1":
45-
// return "/teacher/main";
46-
// case "2":
47-
// return "/student/main";
48-
// }
49-
// }
50-
// return "redirect:/login.jsp";
51-
// }
52-
//
53-
// @RequestMapping("logout")
54-
// public String logout(HttpSession session) {
55-
// session.invalidate();
56-
// return "redirect:/login.jsp";
57-
// }
58-
59-
6028
@RequestMapping("login")
6129
public String login(HttpServletRequest req, Model model, HttpSession session) {
6230
String exceptionClassName = (String) req.getAttribute("shiroLoginFailure");

src/main/resources/spring-mvc-shiro.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
99
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
1010

11+
<!--&lt;!&ndash;shiro的注解驱动&ndash;&gt;-->
1112
<aop:config proxy-target-class="true"></aop:config>
1213
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
1314
<property name="securityManager" ref="securityManager"/>

src/main/resources/spring-mvc.xml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,47 @@
33
xmlns:aop="http://www.springframework.org/schema/aop"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xmlns:mvc="http://www.springframework.org/schema/mvc"
6+
xmlns:context="http://www.springframework.org/schema/context"
67
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
78
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8-
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
9+
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
910

1011
<!--<mvc:interceptors>-->
1112
<!--<mvc:interceptor>-->
1213
<!--<mvc:mapping path="/**"/>-->
1314
<!--<bean class="com.giit.www.system.interceptor.LoginIntercepter"/>-->
1415
<!--</mvc:interceptor>-->
1516
<!--</mvc:interceptors>-->
17+
<context:component-scan base-package="com.giit.www">
18+
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
19+
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
20+
</context:component-scan>
1621

17-
22+
<!--自动注册基于注解风格的DefaultAnnotationHandlerMapping和AnotationMethodHandlerAdapter-->
23+
<!--此处使用conversionService为了自从注册HttpMessageConverter支持@RequestBody和@ResponseBody-->
1824
<mvc:annotation-driven conversion-service="conversionService"/>
1925

26+
<!--用于解析@RequestBody-->
27+
<bean id="conversionService"
28+
class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean>
2029

30+
<!--视图解析器-->
2131
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
2232
<property name="prefix" value="/WEB-INF/view/"/>
2333
<property name="suffix" value=".jsp"/>
2434
</bean>
2535

26-
<bean id="conversionService"
27-
class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean>
28-
<import resource="spring.xml"/>
29-
36+
<!--多部分解析器,用于解析文件上传时context-type为-->
37+
<!--Content-Type:multipart/form-data; boundary=...的情况-->
3038
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
3139
<property name="maxUploadSize" value="5242880"/>
3240
</bean>
3341

42+
<!--第二种处理静态资源的方式-->
43+
<!--<mvc:default-servlet-handler/>-->
3444

35-
<!-- 当在web.xml 中 DispatcherServlet使用 <url-pattern>/</url-pattern> 映射时,能映射静态资源 -->
36-
<mvc:default-servlet-handler/>
37-
38-
<!-- 静态资源映射 -->
39-
<mvc:resources mapping="/static/**" location="/WEB-INF/static/"/>
45+
<!--第三种静态资源映射-->
46+
<!--<mvc:resources mapping="/static/**" location="/WEB-INF/static/"/>-->
4047

4148
<import resource="classpath:spring-mvc-shiro.xml"/>
4249

src/main/resources/spring-shiro.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
<!-- Shiro的Web过滤器 -->
4040
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
4141
<property name="securityManager" ref="securityManager"/>
42-
<property name="loginUrl" value="/login"/>
4342
<property name="filters">
4443
<util:map>
4544
<entry key="authc" value-ref="formAuthenticationFilter"/>

src/main/resources/spring.xml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
xmlns:mybatis="http://mybatis.org/schema/mybatis-spring" xmlns:tx="http://www.springframework.org/schema/tx"
77
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
88

9-
<tx:annotation-driven transaction-manager="transactionManager"/>
10-
<task:annotation-driven/>
9+
<!--自动扫描bean-->
10+
<context:component-scan base-package="com.giit.www">
11+
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
12+
</context:component-scan>
13+
<!--引入外部配置文件-->
1114

12-
<context:annotation-config></context:annotation-config>
13-
<context:component-scan base-package="com.giit.www"/>
1415
<context:property-placeholder location="classpath:db.properties"/>
1516

17+
<!--支持自动化任务-->
18+
<task:annotation-driven/>
19+
20+
<!--数据源-->
1621
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
1722
<property name="driverClassName" value="${jdbc.driver}"/>
1823
<property name="url" value="${jdbc.url}"/>
@@ -22,24 +27,26 @@
2227
<property name="maxIdle" value="5"/>
2328
</bean>
2429

30+
<!--mybatis的SqlSessionFactoy配置-->
2531
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
2632
<property name="configLocation" value="classpath:mybatis-config.xml"/>
2733
<property name="dataSource" ref="dataSource"/>
2834
<property name="typeAliasesPackage" value="com.giit.www.entity,com.giit.www.entity.custom"/>
2935
</bean>
3036

31-
32-
<bean id="transactionManager"
33-
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
34-
<property name="dataSource" ref="dataSource"/>
35-
</bean>
36-
37-
37+
<!--扫描mapper-->
3838
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
3939
<property name="basePackage" value="com.giit.www"/>
4040
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
4141
</bean>
4242

43+
<!--开启事务管理器注解方式-->
44+
<tx:annotation-driven transaction-manager="transactionManager"/>
45+
46+
<bean id="transactionManager"
47+
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
48+
<property name="dataSource" ref="dataSource"/>
49+
</bean>
4350

4451
<!-- 控制器异常处理 -->
4552
<bean id="exceptionHandlerExceptionResolver" class="com.giit.www.exception.DefaultExceptionHandler">

0 commit comments

Comments
 (0)