Skip to content

Commit 114e6dc

Browse files
committed
Revert "Removed unused @controller annotations from controllers."
When I removed @controller annotations I, probably, violate some conventions in Spring and he didn't register my controllers in context after this. This reverts commit a975d89.
1 parent ca93f0c commit 114e6dc

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed

src/main/config/pmd.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,27 @@ public class UserService {
144144

145145
<rule
146146
name="FieldInjectionInControllers"
147-
message="Use constructor injection instead of field injection in controllers"
147+
message="Use constructor injection instead of field injection in @Controller-s"
148148
class="net.sourceforge.pmd.lang.rule.XPathRule"
149149
language="java">
150150

151151
<description>
152-
Prefer constructor injection over field injection in controller classes.
152+
Prefer constructor injection over field injection in @Controller classes.
153153
</description>
154154

155155
<properties>
156156
<property name="xpath">
157157
<value>
158158
<![CDATA[
159-
//ClassOrInterfaceDeclaration[ends-with(@Image, "Controller")]//FieldDeclaration[../Annotation/*/Name[@Image="Autowired" or @Image="Inject"]]
159+
//TypeDeclaration[Annotation/*/Name[@Image="Controller"]]//FieldDeclaration[../Annotation/*/Name[@Image="Autowired" or @Image="Inject"]]
160160
]]>
161161
</value>
162162
</property>
163163
</properties>
164164
<priority>4</priority>
165165
<example>
166166
<![CDATA[
167+
@Controller
167168
public class UserController {
168169
@Inject
169170
private UserDao userDao;

src/main/java/ru/mystamps/web/controller/AccountController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.validation.Valid;
2222

2323
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
24+
import org.springframework.stereotype.Controller;
2425
import org.springframework.ui.Model;
2526
import org.springframework.web.bind.annotation.InitBinder;
2627
import org.springframework.web.bind.annotation.PathVariable;
@@ -42,6 +43,7 @@
4243
import ru.mystamps.web.model.RegisterAccountForm;
4344
import ru.mystamps.web.service.UserService;
4445

46+
@Controller
4547
public class AccountController {
4648

4749
private final UserService userService;

src/main/java/ru/mystamps/web/controller/CountryController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.validation.Valid;
2222

2323
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
24+
import org.springframework.stereotype.Controller;
2425
import org.springframework.ui.Model;
2526
import org.springframework.web.bind.annotation.InitBinder;
2627
import org.springframework.web.bind.annotation.PathVariable;
@@ -36,6 +37,7 @@
3637
import ru.mystamps.web.model.AddCountryForm;
3738
import ru.mystamps.web.service.CountryService;
3839

40+
@Controller
3941
public class CountryController {
4042

4143
private final CountryService countryService;

src/main/java/ru/mystamps/web/controller/ImageController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
import javax.servlet.http.HttpServletResponse;
2323

24+
import org.springframework.stereotype.Controller;
2425
import org.springframework.web.bind.annotation.PathVariable;
2526
import org.springframework.web.bind.annotation.RequestMapping;
2627
import org.springframework.web.bind.annotation.RequestMethod;
2728

2829
import ru.mystamps.web.entity.Image;
2930
import ru.mystamps.web.Url;
3031

32+
@Controller
3133
public class ImageController {
3234

3335
@RequestMapping(value = Url.GET_IMAGE_PAGE, method = RequestMethod.GET)

src/main/java/ru/mystamps/web/controller/NotFoundErrorController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525

26+
import org.springframework.stereotype.Controller;
2627
import org.springframework.web.bind.annotation.RequestHeader;
2728
import org.springframework.web.bind.annotation.RequestMapping;
2829
import org.springframework.web.bind.annotation.RequestMethod;
@@ -32,6 +33,7 @@
3233
import ru.mystamps.web.service.SiteService;
3334
import ru.mystamps.web.support.spring.security.CustomUserDetails;
3435

36+
@Controller
3537
@RequestMapping(Url.NOT_FOUND_PAGE)
3638
public class NotFoundErrorController {
3739
private static final Logger LOG = LoggerFactory.getLogger(NotFoundErrorController.class);

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Map;
2727

2828
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
29+
import org.springframework.stereotype.Controller;
2930
import org.springframework.ui.Model;
3031
import org.springframework.validation.annotation.Validated;
3132
import org.springframework.validation.BindingResult;
@@ -47,6 +48,7 @@
4748
import ru.mystamps.web.service.SeriesService;
4849
import ru.mystamps.web.util.CatalogUtils;
4950

51+
@Controller
5052
public class SeriesController {
5153

5254
private static final Integer SINCE_YEAR = 1840;

0 commit comments

Comments
 (0)