Spring file upload goes to Access denied page

Spring file upload goes to Access denied page

When Spring security is enabled, when I upload a file using multipart, SpringSecurity redirects me to Access denied url.

Refer to https://stackoverflow.com/questions/28225359/file-upload-spring-security
I amend my Initializer as follows!


@EnableScheduling
@EnableAsync
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer{
@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
insertFilters(servletContext, new MultipartFilter());
}
}

This error disappears. I landed in another problem. I’m resolving it now!!

Advertisements

Spring 5 migration: Unable to find setter method for attribute: [commandName]

Spring 5 Migration brings this pain. You will get this error during form submission.

Unable to find setter method for attribute: [commandName]

Command object does not work anymore.

Refer to https://stackoverflow.com/questions/46989072/org-apache-jasper-jasperexception-web-inf-views-home-jsp-line-25-column/48364974
and
https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-5.x

commandName is dead in Spring 5. Replace it with modelAttribute


<form:form modelAttribute="customer" action="customerView" method="post">

It worked! I need to make this change in my workspace now!

Read properties values in Java Spring Controller

To configure the environmental parameters, we read the values from property files. I have a controller which upload the files. The uploaded files will be saved in a location, which is defined in a property file. In this example I shall show you how to read the location name from the property file.


@Controller
@PropertySource("classpath:app.properties")
public class FileUploadController {
  @Value("${upload.Folder}")
  String uploadFolder;
}

I have defined the property in app.properties file which is saved in src folder (or any other path defined in classpath.


upload.Folder=C:\\vss\\upload

Thats it! The variable uploadFolder will be assigned using the values given by app.properties.

No Spring WebApplicationInitializer types detected on classpath

Wah, what a stupid error it was!

My Spring web app, which was running smoothly, refused to start. I don’t find any logs in log4j or tomcat log. Only clue I had was –

No Spring WebApplicationInitializer types detected on classpath

Here is how I solved it –

  1. Stop the tomcat
  2. Clean and build all eclipse projects
  3. Goto server tab and select the tomcat server. Press clean. Press clean work directory.
  4. Right click on the tomcat and remove it.
  5. Delete the tomcat from the eclipse run times
  6. Add tomcat server to the eclipse servers again
  7. Start the application

 

javax.validation.ValidationException: HV000183: Unable to load ‘javax.el.ExpressionFactory’. Check that you have the EL dependencies on the classpath, or use ParameterMessageInterpolator instead

I got this exception when I executed my newly written junit test for a Spring DAO with Hibernate Validations.

After adding javax.el to pom, this is resolved.


<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.4</version>
</dependency>