Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8467265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:35:32+00:00 2026-06-10T15:35:32+00:00

I have annotated my fields in my model and am using the @Valid annotation

  • 0

I have annotated my fields in my model and am using the @Valid annotation on my post controller but it appears to be performing no validation (result.errors is empty)

Any ideas what might be causing this?

Java based configuration:

@FeatureConfiguration
public class MvcFeatures {

    @Feature
    public MvcAnnotationDriven annotationDriven() {
        return new MvcAnnotationDriven();
    }

    @Feature
    public MvcResources css() {
        return new MvcResources("/css/**", "/css/");
    }

    @Feature
    public MvcResources js() {
        return new MvcResources("/js/**", "/js/");
    }

    @Feature
    public MvcViewControllers viewController() {
        return new MvcViewControllers("/", "home");
    }

    @Feature
    public ComponentScanSpec componentScan() {
        return new ComponentScanSpec("com.webapp")
                .excludeFilters(new AnnotationTypeFilter(Configuration.class),
                        new AnnotationTypeFilter(FeatureConfiguration.class));
    }

}

Controller:

@Controller
public class UserController extends AppController
{
    static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/registration", method = RequestMethod.GET)
    public ModelAndView get()
    {

        ModelAndView modelAndView = new ModelAndView(Consts.MODEL_RESISTER_PAGE);
        modelAndView.addObject("user", new User());

        return modelAndView;
    }

    @RequestMapping(value = "/registration", method = RequestMethod.POST)
    public ModelAndView post(@Valid User user, BindingResult result)
    {

        if (result.hasErrors())
        {
            ModelAndView modelAndView = new ModelAndView(
                    Consts.MODEL_RESISTER_PAGE);
            modelAndView.addObject("user", result.getModel());
            return modelAndView;
        }
        else
        {
            // SAVE HERE
            ModelAndView modelAndView = new ModelAndView(
                    Consts.MODEL_RESISTER_PAGE);
            return modelAndView;
        }
    }
}

Model:

@Entity
public class User implements Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -5232533507244034448L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotEmpty
    @Size(min=2, max=15)
    private String firstname;

    @NotEmpty
    @Size(min=2, max=15)
    private String surname;

    @NotEmpty
    @Email
    private String email;

    @NotEmpty
    @Size(min=6, max=10)
    private String password;

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String getFirstname()
    {
        return firstname;
    }

    public void setFirstname(String firstname)
    {
        this.firstname = firstname;
    }

    public String getSurname()
    {
        return surname;
    }

    public void setSurname(String surname)
    {
        this.surname = surname;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }
}

add.html (Using thymeleaf view resolver)

<form id="registrationForm" action="#"
        th:action="@{/registration}" th:object="${user}" method="post"
        class="clearfix">

         <legend>Registration</legend>

        <div class="input">
          <input type="text" th:field="*{firstname}"
            placeholder="Firstname" th:class="${#fields.hasErrors('firstname')}? 'fieldError'"
             />
        </div>

        <div class="input">
          <input type="text" th:field="*{surname}" placeholder="Surname" />
        </div>

        <div class="input">
          <input type="text" th:field="*{email}" placeholder="Email" />
        </div>

        <div class="input">
          <input type="password" th:field="*{password}"
            placeholder="Password" />
        </div>

        <div class="clearfix">
          <input type="submit" class="btn btn-success btn-large" value="Register" />
        </div>

      </form>

Pom:

<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>ConsumerApplicaton</groupId>
    <artifactId>ConsumerApplicaton</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>springsource-milestone</id>
            <name>Spring Framework Milestone Repository</name>
            <url>http://maven.springframework.org/milestone</url>
        </repository>
    </repositories>

    <dependencies>
        <!-- spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- thymeleaf -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>${thymeleaf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring3</artifactId>
            <version>${thymeleaf.version}</version>
        </dependency>

        <!-- persistence -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.6.9.Final</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>

        <!-- json, xml, atom -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>${jackson-mapper-asl.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>${jaxb-api.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- DB -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
            <scope>runtime</scope>
        </dependency>

        <!-- logging -->

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.1</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Various -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>${cglib.version}</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>ConsumerApplicaton</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <!-- VERSIONS -->
        <!-- <spring.version>3.1.0.RELEASE</spring.version> -->
        <spring.version>3.1.0.M1</spring.version>
        <cglib.version>2.2.2</cglib.version>

        <thymeleaf.version>2.0.11</thymeleaf.version>

        <jackson-mapper-asl.version>1.9.5</jackson-mapper-asl.version>
        <jaxb-api.version>2.2.6</jaxb-api.version>

        <!-- VERSIONS - persistence -->
        <mysql-connector-java.version>5.1.18</mysql-connector-java.version> <!-- latest version on: 02.10.2011 - http://dev.mysql.com/downloads/connector/j/ -->
        <hibernate.version>4.1.0.Final</hibernate.version>

        <!-- VERSIONS - logging -->
        <org.slf4j.version>1.6.4</org.slf4j.version>
    </properties>

</project>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:35:34+00:00Added an answer on June 10, 2026 at 3:35 pm

    @Feature is no longer supported. This was implemented in Spring 3.1.0.M1 and then removed in favour of @Enable style annotations in 3.1.0.M2.

    The best approach here is to move to 3.1.1.RELEASE and use @Configuration and friends.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an annotated controller with a method that expects a model and a
I have a method annotated with @PrePersist annotation but I've seen that when this
I have annotated my classes with @Repository, @Resource, @Component, @Service annotations but these classes
I'm using Hibernate as ORM and I have my DAOs annotated with @Repository .
I have the following model class Plugin(models.Model): name = models.CharField(max_length=50) # more fields which
I have a model called Story that has two integer fields called views and
For example, I have a model Posts and Comments. Post.objects.annotate(Count('comment')) I am making such
I have the following classes in my JPA model (getters, setters, and irrelevant fields
For a simple validation of multiple required fields i am using a custom validator
I have an app using Spring, JPA (Hibernate) and the Java validation framework (Hibernate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.