How to get error text in controller from BindingResult?

Disclaimer: I still do not use Spring-MVC 3.0 But i think the same approach used by Spring 2.5 can fullfil your needs for (Object object : bindingResult.getAllErrors()) { if(object instanceof FieldError) { FieldError fieldError = (FieldError) object; System.out.println(fieldError.getCode()); } if(object instanceof ObjectError) { ObjectError objectError = (ObjectError) object; System.out.println(objectError.getCode()); } } I hope it can … Read more

Spring Boot @Value Properties

I had the same problem like you. Here’s my error code. @Component public class GetExprsAndEnvId { @Value(“hello”) private String Mysecret; public GetExprsAndEnvId() { System.out.println(“construct”); } public void print(){ System.out.println(this.Mysecret); } public String getMysecret() { return Mysecret; } public void setMysecret(String mysecret) { Mysecret = mysecret; } } This is no problem like this, but we … Read more

Struts2 + Spring Security 2.06: Valuestack is null when attempting to use @Secured on an Action method

I just wonder, this problem occurs if you use the default configuration of Spring Security, where it expects ROLE_ prefixed names. See this question: How do I use custom roles/authorities in Spring Security? You are using the default configuration witch expects that roles starts with the “ROLE_” prefix. You will have to add a custom … Read more

Difference between Spring annotations

@Component and @Configuration are indeed very different types of annotations. @Component and similar annotations (@Service, @Repository, etc. )and its JSR-330 counterpart @Named allow you to declare beans that are to be picked up by autoscanning with <context:component-scan/> or @ComponentScan they register the bean definition for the classes, so they are roughly equivalent to declaring the … Read more

Is it possible to set a bean name using annotations in Spring Framework?

What you are asking is already available in Spring reference By default, configuration classes use a @Bean method’s name as the name of the resulting bean. This functionality can be overridden, however, with the name attribute. @Configuration public class AppConfig { @Bean(name = “myFoo”) public Foo foo() { return new Foo(); } }

Difference between @EntityScan and @ComponentScan

The @ComponentScan annotation is used to automatically create beans for every class annotated with @Component, @Service, @Controller, @RestController, @Repository, … and adds them to the Spring container (allowing them to be @Autowired). The @EntityScan on the other hand does not create beans as far as I know. It only identifies which classes should be used … Read more

What is a Spring “stereotype”?

The JavaDoc says a bit about it. Annotations denoting the roles of types or methods in the overall architecture (at a conceptual, rather than implementation, level). The noun definition of stereotype from Merriam-Webster says this: something conforming to a fixed or general pattern; especially : a standardized mental picture that is held in common by … Read more

Benefits of JavaConfig over XML configurations in Spring?

There are some advantages Java is type safe. Compiler will report issues if you are configuring right bean class qualifiers. XML based on configuration can quickly grow big. [Yes we can split and import but still] Search is much simpler, refactoring will be bliss. Finding a bean definition will be far easier. There are still … Read more

Spring @Value escape colon(:) in default value

Update: For spring 4.2 and higher, no single quotes are needed. Spring will see the first colon as special, and use all the rest as a single string value. For spring 4.2 and higher, @Value(“${prop.url:http://myurl.com}”) For the previous versions, I believe single quotes will do the trick: @Value(“${prop.url:’http://myurl.com’}”)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)