What is package-info.java and how can I add it to my project?

Is used to store javadoc description. You can find it at 7.4.1. Named Packages of the The Java® Language Specification: It is recommended that package-info.java, if it is present, take the place of package.html for javadoc and other similar documentation generation systems. If this file is present, the documentation generation tool should look for the … Read more

Spring MVC: How to use a request-scoped bean inside a spawned thread?

OK, by reading the code in SimpleThreadScope that comes with Spring I think you can create a SimpleInheritableThreadScope by using an InheritableThreadLocal instead. Then just use a bit of xml to register your custom scope: <bean class=”org.springframework.beans.factory.config.CustomScopeConfigurer”> <property name=”scopes”> <map> <entry key=”thread-inherited”> <bean class=”org.mael.spring.context.support.SimpleInheritableThreadScope”/> </entry> </map> </property> </bean> This means that when you create a … Read more

Spring @RequestBody containing a list of different types (but same interface)

You should use the Jackson annotations @JsonTypeInfo and @JsonSubTypes to achieve polymorphic json. The annotations go on the Animal base class. @JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = “type”) @JsonSubTypes({@JsonSubTypes.Type(value = Dog.class, name = “Dog”), @JsonSubTypes.Type(value = Cat.class, name = “Cat”)}) public abstract class Animal { }

Form submit in Spring MVC 3 – explanation

The @ModelAttribute annotation in this case is used to identify an object that Spring should add as a model attribute. Model attributes are an abstraction from the HttpServletRequest attributes. Basically, they are objects identified by some key that will find their way into the HttpServletRequest attributes. You can do this by manually adding an attribute … Read more

What is the meaning of {id:.+} in a Spring MVC requestmapping handler method?

The syntax of a path variable in a spring MVC controller requestmapping is {variable_name:regular_expression}. You can optionally omit the regular expression, which leads to what you see more often, {id}. So, for the example /index/{endpoint}/{type}/{id:.+} the variable name is id and the regular expression is .+ (see below reference to spring docs). The regular expression … Read more

How exactly are the root context and the dispatcher servlet context into a Spring MVC web application?

Root Context The root-context in a Spring application is the ApplicationContext that is loaded by the ContextLoaderListener. This context should have globally available resources like services, repositories, infrastructure beans (DataSource, EntityManagerFactorys etc.) etc. The ContextLoaderListener registers this context in the ServletContext under the name org.springframework.web.context.WebApplicationContext.ROOT. If you load an ApplicationContext yourself and register it with … Read more

How to disable csrf in Spring using application.properties?

As the WebSecurityConfigurerAdapter uses an imperative approach you can inject the value of the security.enable-csrf variable and disable CSRF when it be false. You are right, I think this should work out of the box. @Configuration public class AuthConfig extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsService userDetailsService; @Value(“${security.enable-csrf}”) private boolean csrfEnabled; @Override protected void configure(AuthenticationManagerBuilder auth) … Read more

SPRING REST: The request was rejected because no multipart boundary was found

The problem isn’t in your code – it’s in your request. You’re missing boundary in your multipart request. As it said in specification: The Content-Type field for multipart entities requires one parameter, “boundary”, which is used to specify the encapsulation boundary. The encapsulation boundary is defined as a line consisting entirely of two hyphen characters … Read more

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