I had successfully run my spring boot application in localhost.
But when I had run it from the CWP panel tomcat server, I am getting the error given below. How to resolve this error? Do I need anything else to run on a CWP panel tomcat server?
Steps which I had followed
Extends the SpringBootServletInitializer class in the main class.
@SpringBootApplication public class GDriveAppJavaApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure( SpringApplicationBuilder builder) { return builder.sources(GDriveAppJavaApplication.class); } public static void main(String[] args) { SpringApplication.run(GDriveAppJavaApplication.class, args); } }
Update packaging JAR to WAR
Added Tomcat starter dependency with scope as provided
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
Application properties
server.servlet.context-path=/GDriveAppJava
Generated war file(GDriveAppJava) and copied to webapps folder in the tomcat as shown below.
Controller file
@RestController @AllArgsConstructor public class FileController { @Autowired private FileManager fileManager; @Autowired private FileRepository fileRepository; @PostMapping(value = "/upload/{user_id}") public ResponseEntity<FileEntity> uploadFIle(@RequestParam("file") MultipartFile file,@PathVariable String user_id){ FileEntity updated = fileManager.uploadFile(file, user_id); return new ResponseEntity<FileEntity>(updated, HttpStatus.OK); } @GetMapping(path="/viewByUserId/{user_id}") public List<FileEntity> viewByUserid(@PathVariable String user_id) { return fileRepository.findByUserId(user_id); } @GetMapping("/downloadFile/{file_id}") public void download(@PathVariable String file_id, HttpServletResponse response) throws IOException, GeneralSecurityException { fileManager.downloadFile(file_id, response.getOutputStream()); } @GetMapping(path="/viewByFileId/{file_id}") public List<FileEntity> viewByFileId(@PathVariable String file_id) { return fileRepository.findByFileId(file_id); }
}
Application properties
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:jdbc:mysql://${MYSQL_HOST:localhost}:3306/user123_gdriveapp
spring.datasource.username=user123//my server username
spring.datasource.password=password123//my server password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql: true
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
server.servlet.context-path=/GDriveAppJava
Step 1: You need to generate a war file and deploy it to the tomcat server. Referring to https://codezup.com/deploy-spring-boot-war-to-external-tomcat/ for generating war file.
Step 2: Search the war file to target folder. Then rename the war file. for example: gdapp.war. Then depoloy the .war file to the tomcat server.
Step 3: Access the application using the file name in the URL. example: gdapp/GDriveAppJava/...
Note: Make sure you have configured your database properly.