Migrated modules using parent-spring-5:
ethereum persistence-modules/spring-data-elasticsearch persistence-modules/spring-data-mongodb spring-dispatcher-servlet spring-mvc-forms-jsp spring-mvc-java
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
### Relevant Articles:
|
||||
- [A Guide to Flips for Spring](http://www.baeldung.com/flips-spring)
|
||||
- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari)
|
||||
- [Spring JSON-P with Jackson](http://www.baeldung.com/spring-jackson-jsonp)
|
||||
|
||||
@@ -52,6 +52,21 @@
|
||||
<!-- Check for the most recent available version: https://projectlombok.org/changelog.html -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
</dependency>
|
||||
<!-- Provided -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -71,6 +86,7 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<start-class>com.baeldung.flips.ApplicationConfig</start-class>
|
||||
<flips-web.version>1.0.1</flips-web.version>
|
||||
<lombok.version>1.16.18</lombok.version>
|
||||
<h2database.version>1.4.197</h2database.version>
|
||||
|
||||
@@ -3,9 +3,15 @@ package com.baeldung.flips;
|
||||
import org.flips.describe.config.FlipWebContextConfiguration;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {
|
||||
DataSourceAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class })
|
||||
@Import(FlipWebContextConfiguration.class)
|
||||
public class ApplicationConfig {
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.jsonp;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@SpringBootApplication(exclude = {
|
||||
DataSourceAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class })
|
||||
@PropertySource("classpath:jsonp-application.properties")
|
||||
public class JsonPApplication extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(JsonPApplication.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(JsonPApplication.class, args);
|
||||
}
|
||||
}
|
||||
38
spring-4/src/main/java/com/baeldung/jsonp/model/Company.java
Normal file
38
spring-4/src/main/java/com/baeldung/jsonp/model/Company.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.jsonp.model;
|
||||
|
||||
public class Company {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
public Company() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Company(final long id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Company [id=" + id + ", name=" + name + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.jsonp.web.controller;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.baeldung.jsonp.model.Company;
|
||||
|
||||
@Controller
|
||||
public class CompanyController {
|
||||
|
||||
@RequestMapping(value = "/companyResponseBody", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public Company getCompanyResponseBody() {
|
||||
final Company company = new Company(2, "ABC");
|
||||
return company;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/companyResponseEntity", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Company> getCompanyResponseEntity() {
|
||||
final Company company = new Company(3, "123");
|
||||
return new ResponseEntity<Company>(company, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.jsonp.web.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class IndexController {
|
||||
|
||||
@RequestMapping()
|
||||
public String retrieveIndex() {
|
||||
return "index";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.jsonp.web.controller.advice;
|
||||
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;
|
||||
|
||||
// AbstractJsonpResponseBodyAdvice was deprecated in favor of configuring CORS properly
|
||||
// We still want to cover the usage of JSON-P in our articles, therefore we don't care that it was deprecated.
|
||||
@SuppressWarnings("deprecation")
|
||||
@ControllerAdvice
|
||||
public class JsonpControllerAdvice extends AbstractJsonpResponseBodyAdvice {
|
||||
|
||||
public JsonpControllerAdvice() {
|
||||
super("callback");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,4 +2,4 @@ feature.foo.by.id=Y
|
||||
feature.new.foo=Y
|
||||
last.active.after=2018-03-14T00:00:00Z
|
||||
first.active.after=2999-03-15T00:00:00Z
|
||||
logging.level.org.flips=info
|
||||
logging.level.org.flips=info
|
||||
|
||||
2
spring-4/src/main/resources/jsonp-application.properties
Normal file
2
spring-4/src/main/resources/jsonp-application.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
spring.mvc.view.prefix=/WEB-INF/jsp/
|
||||
spring.mvc.view.suffix=.jsp
|
||||
66
spring-4/src/main/webapp/WEB-INF/jsp/index.jsp
Normal file
66
spring-4/src/main/webapp/WEB-INF/jsp/index.jsp
Normal file
@@ -0,0 +1,66 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
pageEncoding="ISO-8859-1" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="ISO-8859-1">
|
||||
<title>Company Data</title>
|
||||
<script src="https://code.jquery.com/jquery-3.1.0.js"
|
||||
integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk="
|
||||
crossorigin="anonymous"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#ResponseBody-button').click(function() {
|
||||
$.ajax({
|
||||
url: 'http://localhost:8080/spring-mvc-java/companyResponseBody?callback=getCompanyData',
|
||||
data: {
|
||||
format: 'json'
|
||||
},
|
||||
type: 'GET',
|
||||
jsonpCallback:'getCompanyData',
|
||||
dataType: 'jsonp',
|
||||
error: function() {
|
||||
$('#infoResponseBody').html('<p>An error has occurred</p>');
|
||||
},
|
||||
success: function(data) {
|
||||
console.log("sucess");
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#ResponseEntity-button').click(function() {
|
||||
console.log("ResponseEntity");
|
||||
$.ajax({
|
||||
url: 'http://localhost:8080/spring-mvc-java/companyResponseEntity?callback=getCompanyData',
|
||||
data: {
|
||||
format: 'json'
|
||||
},
|
||||
type: 'GET',
|
||||
jsonpCallback:'getCompanyData',
|
||||
dataType: 'jsonp',
|
||||
error: function() {
|
||||
$('#infoResponseEntity').html('<p>An error has occurred</p>');
|
||||
},
|
||||
success: function(data) {
|
||||
console.log("sucess");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getCompanyData(data) {
|
||||
$("#response").append("<b>ID:</b> "+data.id+"<br/>");
|
||||
$("#response").append("<b>NAME:</b> "+data.name+"<br/>");
|
||||
$("#response").append("<br/>");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!--Using @ResponseBody -->
|
||||
<button id="ResponseBody-button">Send AJAX JSON-P request!</button>
|
||||
|
||||
<div id="response"></div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user