This commit is contained in:
kkaravitis
2020-03-22 22:13:01 +02:00
489 changed files with 11377 additions and 1613 deletions
+1
View File
@@ -20,6 +20,7 @@
<module>spring-boot-annotations</module>
<module>spring-boot-artifacts</module>
<module>spring-boot-autoconfiguration</module>
<module>spring-boot-basic-customization</module>
<module>spring-boot-bootstrap</module>
<module>spring-boot-client</module>
<module>spring-boot-config-jpa-error</module>
@@ -0,0 +1,13 @@
## Spring Boot Basic Customization
This module contains articles about Spring Boot customization
### Relevant Articles:
- [How to Change the Default Port in Spring Boot](https://www.baeldung.com/spring-boot-change-port)
- [Using Custom Banners in Spring Boot](https://www.baeldung.com/spring-boot-custom-banners)
- [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer)
- [Spring Boot: Customize Whitelabel Error Page](https://www.baeldung.com/spring-boot-custom-error-page)
- [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class)
- [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter)
- [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon)
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-basic-customization</artifactId>
<name>spring-boot-basic-customization</name>
<packaging>jar</packaging>
<description>Module For Spring Boot Basic Customization</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<!-- The main class to start by executing "java -jar" -->
<start-class>com.baeldung.changeport.CustomApplication</start-class>
</properties>
</project>
@@ -1,10 +1,8 @@
package com.baeldung.bootcustomfilters;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.bootcustomfilters.filters.RequestResponseLoggingFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FilterConfig {
@@ -1,16 +1,15 @@
package com.baeldung.bootcustomfilters.controller;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import com.baeldung.bootcustomfilters.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.bootcustomfilters.model.User;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
/**
* Rest controller for User
@@ -1,21 +1,15 @@
package com.baeldung.bootcustomfilters.filters;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* A servlet filter to log request and response
* The logging implementation is pretty native and for demonstration only
@@ -1,20 +1,14 @@
package com.baeldung.bootcustomfilters.filters;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* A filter to create transaction before and commit it once request completes
* The current implemenatation is just for demo
@@ -2,10 +2,8 @@ package com.baeldung.errorhandling;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.errorhandling")
@SpringBootApplication(scanBasePackages = "com.baeldung.errorhandling")
public class ErrorHandlingApplication {
public static void main(String [] args) {
@@ -1,10 +1,10 @@
package com.baeldung.failureanalyzer;
import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.security.RolesAllowed;
@SpringBootApplication
public class FailureAnalyzerApplication {
@RolesAllowed("*")
@@ -1,9 +1,9 @@
package com.baeldung.failureanalyzer;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class MyService {
@@ -0,0 +1,12 @@
package com.baeldung.favicon;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FaviconApplication {
public static void main(String[] args) {
SpringApplication.run(FaviconApplication.class, args);
}
}
@@ -1,8 +1,4 @@
package com.baeldung.springbootmvc.config;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
package com.baeldung.favicon.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -14,8 +10,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Configuration
public class FaviconConfiguration {
@Bean
public SimpleUrlHandlerMapping myFaviconHandlerMapping() {
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
@@ -33,7 +34,7 @@ public class FaviconConfiguration {
return requestHandler;
}
// @Controller
// @Controller
static class FaviconController {
@RequestMapping(value = "favicon.ico", method = RequestMethod.GET)
@@ -0,0 +1,10 @@
#server
server.port=9000
spring.mvc.servlet.path=/
server.servlet.context-path=/
server.error.whitelabel.enabled=false
#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration
#for Spring Boot 2.0+
#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
@@ -0,0 +1,7 @@
#spring.banner.charset=UTF-8
#spring.banner.location=classpath:banner.txt
#spring.banner.image.location=classpath:banner.gif
#spring.banner.image.width= //TODO
#spring.banner.image.height= //TODO
#spring.banner.image.margin= //TODO
#spring.banner.image.invert= //TODO

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<body>
<h1> Sorry, we couldn't find the page you were looking for. </h1>
<p><a href="/">Go Home</a></p>
</body>
</html>
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1> Sorry, something went wrong! </h1>
<h2>We're fixing it.</h2>
<p><a href="/">Go Home</a></p>
</body>
</html>
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>
<h1> Something went wrong! </h1>
<h2>Our Engineers are on it.</h2>
<p><a href="/">Go Home</a></p>
</body>
</html>
@@ -0,0 +1,8 @@
<html>
<head>
<title>RESOURCE NOT FOUND</title>
</head>
<body>
<h1>404 RESOURCE NOT FOUND</h1>
</body>
</html>
@@ -0,0 +1,6 @@
<html>
<body>
<h1>Welcome Home</h1>
<p><strong>Success!</strong> It is working as we expected.</p>
</body>
</html>
@@ -1,18 +1,16 @@
package com.baeldung.failureanalyzer;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import java.util.stream.Collectors;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.baeldung.failureanalyzer.utils.ListAppender;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.SpringApplication;
import com.baeldung.failureanalyzer.utils.ListAppender;
import java.util.Collection;
import java.util.stream.Collectors;
import ch.qos.logback.classic.spi.ILoggingEvent;
import static org.assertj.core.api.Assertions.assertThat;
public class FailureAnalyzerAppIntegrationTest {
@@ -1,11 +1,11 @@
package com.baeldung.failureanalyzer.utils;
import java.util.ArrayList;
import java.util.List;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import java.util.ArrayList;
import java.util.List;
public class ListAppender extends AppenderBase<ILoggingEvent> {
static private List<ILoggingEvent> events = new ArrayList<>();
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource="org/springframework/boot/logging/logback/base.xml" />
resource="org/springframework/boot/logging/logback/base.xml" />
<appender name="LISTAPPENDER"
class="com.baeldung.failureanalyzer.utils.ListAppender">
class="com.baeldung.failureanalyzer.utils.ListAppender">
</appender>
<logger
name="org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter">
name="org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter">
<appender-ref ref="LISTAPPENDER" />
</logger>
<root level="info">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
</configuration>
@@ -9,3 +9,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Guide to ShedLock with Spring](https://www.baeldung.com/shedlock-spring)
- [A Guide to the Problem Spring Web Library](https://www.baeldung.com/problem-spring-web)
- [Generating Barcodes and QR Codes in Java](https://www.baeldung.com/java-generating-barcodes-qr-codes)
@@ -53,8 +53,41 @@
<version>${shedlock.version}</version>
</dependency>
<!-- Barcodes -->
<dependency>
<groupId>net.sourceforge.barbecue</groupId>
<artifactId>barbecue</artifactId>
<version>${barbecue.version}</version>
</dependency>
<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j</artifactId>
<version>${barcode4j.version}</version>
</dependency>
<dependency>
<groupId>com.github.kenglxn.qrgen</groupId>
<artifactId>javase</artifactId>
<version>${qrgen.version}</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>${zxing.version}</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>${zxing.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
<finalName>spring-boot-libraries</finalName>
<resources>
@@ -153,6 +186,10 @@
<modelmapper.version>2.3.2</modelmapper.version>
<problem-spring-web.version>0.23.0</problem-spring-web.version>
<shedlock.version>2.1.0</shedlock.version>
<barbecue.version>1.5-beta1</barbecue.version>
<barcode4j.version>2.1</barcode4j.version>
<qrgen.version>2.6.0</qrgen.version>
<zxing.version>3.3.0</zxing.version>
</properties>
</project>
@@ -0,0 +1,99 @@
package com.baeldung.barcodes;
import com.baeldung.barcodes.generators.BarbecueBarcodeGenerator;
import com.baeldung.barcodes.generators.Barcode4jBarcodeGenerator;
import com.baeldung.barcodes.generators.QRGenBarcodeGenerator;
import com.baeldung.barcodes.generators.ZxingBarcodeGenerator;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.awt.image.BufferedImage;
@RestController
@RequestMapping("/barcodes")
public class BarcodesController {
//Barbecue library
@GetMapping(value = "/barbecue/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barbecueUPCABarcode(@PathVariable("barcode") String barcode) throws Exception {
return okResponse(BarbecueBarcodeGenerator.generateUPCABarcodeImage(barcode));
}
@GetMapping(value = "/barbecue/ean13/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barbecueEAN13Barcode(@PathVariable("barcode") String barcode) throws Exception {
return okResponse(BarbecueBarcodeGenerator.generateEAN13BarcodeImage(barcode));
}
@PostMapping(value = "/barbecue/code128", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barbecueCode128Barcode(@RequestBody String barcode) throws Exception {
return okResponse(BarbecueBarcodeGenerator.generateCode128BarcodeImage(barcode));
}
@PostMapping(value = "/barbecue/pdf417", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barbecuePDF417Barcode(@RequestBody String barcode) throws Exception {
return okResponse(BarbecueBarcodeGenerator.generatePDF417BarcodeImage(barcode));
}
//Barcode4j library
@GetMapping(value = "/barcode4j/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barcode4jUPCABarcode(@PathVariable("barcode") String barcode) {
return okResponse(Barcode4jBarcodeGenerator.generateUPCABarcodeImage(barcode));
}
@GetMapping(value = "/barcode4j/ean13/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barcode4jEAN13Barcode(@PathVariable("barcode") String barcode) {
return okResponse(Barcode4jBarcodeGenerator.generateEAN13BarcodeImage(barcode));
}
@PostMapping(value = "/barcode4j/code128", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barcode4jCode128Barcode(@RequestBody String barcode) {
return okResponse(Barcode4jBarcodeGenerator.generateCode128BarcodeImage(barcode));
}
@PostMapping(value = "/barcode4j/pdf417", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> barcode4jPDF417Barcode(@RequestBody String barcode) {
return okResponse(Barcode4jBarcodeGenerator.generatePDF417BarcodeImage(barcode));
}
//Zxing library
@GetMapping(value = "/zxing/upca/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingUPCABarcode(@PathVariable("barcode") String barcode) throws Exception {
return okResponse(ZxingBarcodeGenerator.generateUPCABarcodeImage(barcode));
}
@GetMapping(value = "/zxing/ean13/{barcode}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingEAN13Barcode(@PathVariable("barcode") String barcode) throws Exception {
return okResponse(ZxingBarcodeGenerator.generateEAN13BarcodeImage(barcode));
}
@PostMapping(value = "/zxing/code128", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingCode128Barcode(@RequestBody String barcode) throws Exception {
return okResponse(ZxingBarcodeGenerator.generateCode128BarcodeImage(barcode));
}
@PostMapping(value = "/zxing/pdf417", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingPDF417Barcode(@RequestBody String barcode) throws Exception {
return okResponse(ZxingBarcodeGenerator.generatePDF417BarcodeImage(barcode));
}
@PostMapping(value = "/zxing/qrcode", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> zxingQRCode(@RequestBody String barcode) throws Exception {
return okResponse(ZxingBarcodeGenerator.generateQRCodeImage(barcode));
}
//QRGen
@PostMapping(value = "/qrgen/qrcode", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<BufferedImage> qrgenQRCode(@RequestBody String barcode) throws Exception {
return okResponse(QRGenBarcodeGenerator.generateQRCodeImage(barcode));
}
private ResponseEntity<BufferedImage> okResponse(BufferedImage image) {
return new ResponseEntity<>(image, HttpStatus.OK);
}
}
@@ -0,0 +1,23 @@
package com.baeldung.barcodes;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.BufferedImageHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import java.awt.image.BufferedImage;
@SpringBootApplication
public class SpringBootApp {
public static void main(String[] args) {
SpringApplication.run(SpringBootApp.class, args);
}
@Bean
public HttpMessageConverter<BufferedImage> createImageHttpMessageConverter() {
return new BufferedImageHttpMessageConverter();
}
}
@@ -0,0 +1,43 @@
package com.baeldung.barcodes.generators;
import net.sourceforge.barbecue.Barcode;
import net.sourceforge.barbecue.BarcodeFactory;
import net.sourceforge.barbecue.BarcodeImageHandler;
import java.awt.*;
import java.awt.image.BufferedImage;
public class BarbecueBarcodeGenerator {
private static final Font BARCODE_TEXT_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 14);
public static BufferedImage generateUPCABarcodeImage(String barcodeText) throws Exception {
Barcode barcode = BarcodeFactory.createUPCA(barcodeText); //checksum is automatically added
barcode.setFont(BARCODE_TEXT_FONT);
barcode.setResolution(400);
return BarcodeImageHandler.getImage(barcode);
}
public static BufferedImage generateEAN13BarcodeImage(String barcodeText) throws Exception {
Barcode barcode = BarcodeFactory.createEAN13(barcodeText); //checksum is automatically added
barcode.setFont(BARCODE_TEXT_FONT);
return BarcodeImageHandler.getImage(barcode);
}
public static BufferedImage generateCode128BarcodeImage(String barcodeText) throws Exception {
Barcode barcode = BarcodeFactory.createCode128(barcodeText);
barcode.setFont(BARCODE_TEXT_FONT);
return BarcodeImageHandler.getImage(barcode);
}
public static BufferedImage generatePDF417BarcodeImage(String barcodeText) throws Exception {
Barcode barcode = BarcodeFactory.createPDF417(barcodeText);
barcode.setFont(BARCODE_TEXT_FONT);
return BarcodeImageHandler.getImage(barcode);
}
}
@@ -0,0 +1,46 @@
package com.baeldung.barcodes.generators;
import org.krysalis.barcode4j.impl.code128.Code128Bean;
import org.krysalis.barcode4j.impl.pdf417.PDF417Bean;
import org.krysalis.barcode4j.impl.upcean.EAN13Bean;
import org.krysalis.barcode4j.impl.upcean.UPCABean;
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
import java.awt.image.BufferedImage;
public class Barcode4jBarcodeGenerator {
public static BufferedImage generateUPCABarcodeImage(String barcodeText) {
UPCABean barcodeGenerator = new UPCABean();
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
barcodeGenerator.generateBarcode(canvas, barcodeText);
return canvas.getBufferedImage();
}
public static BufferedImage generateEAN13BarcodeImage(String barcodeText) {
EAN13Bean barcodeGenerator = new EAN13Bean();
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
barcodeGenerator.generateBarcode(canvas, barcodeText);
return canvas.getBufferedImage();
}
public static BufferedImage generateCode128BarcodeImage(String barcodeText) {
Code128Bean barcodeGenerator = new Code128Bean();
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
barcodeGenerator.generateBarcode(canvas, barcodeText);
return canvas.getBufferedImage();
}
public static BufferedImage generatePDF417BarcodeImage(String barcodeText) {
PDF417Bean barcodeGenerator = new PDF417Bean();
BitmapCanvasProvider canvas = new BitmapCanvasProvider(160, BufferedImage.TYPE_BYTE_BINARY, false, 0);
barcodeGenerator.setColumns(10);
barcodeGenerator.generateBarcode(canvas, barcodeText);
return canvas.getBufferedImage();
}
}
@@ -0,0 +1,21 @@
package com.baeldung.barcodes.generators;
import net.glxn.qrgen.javase.QRCode;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class QRGenBarcodeGenerator {
public static BufferedImage generateQRCodeImage(String barcodeText) throws Exception {
ByteArrayOutputStream stream = QRCode
.from(barcodeText)
.withSize(250, 250)
.stream();
ByteArrayInputStream bis = new ByteArrayInputStream(stream.toByteArray());
return ImageIO.read(bis);
}
}
@@ -0,0 +1,51 @@
package com.baeldung.barcodes.generators;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;
import com.google.zxing.oned.EAN13Writer;
import com.google.zxing.oned.UPCAWriter;
import com.google.zxing.pdf417.PDF417Writer;
import com.google.zxing.qrcode.QRCodeWriter;
import java.awt.image.BufferedImage;
public class ZxingBarcodeGenerator {
public static BufferedImage generateUPCABarcodeImage(String barcodeText) throws Exception {
UPCAWriter barcodeWriter = new UPCAWriter();
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.UPC_A, 300, 150);
return MatrixToImageWriter.toBufferedImage(bitMatrix);
}
public static BufferedImage generateEAN13BarcodeImage(String barcodeText) throws Exception {
EAN13Writer barcodeWriter = new EAN13Writer();
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.EAN_13, 300, 150);
return MatrixToImageWriter.toBufferedImage(bitMatrix);
}
public static BufferedImage generateCode128BarcodeImage(String barcodeText) throws Exception {
Code128Writer barcodeWriter = new Code128Writer();
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.CODE_128, 300, 150);
return MatrixToImageWriter.toBufferedImage(bitMatrix);
}
public static BufferedImage generatePDF417BarcodeImage(String barcodeText) throws Exception {
PDF417Writer barcodeWriter = new PDF417Writer();
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.PDF_417, 700, 700);
return MatrixToImageWriter.toBufferedImage(bitMatrix);
}
public static BufferedImage generateQRCodeImage(String barcodeText) throws Exception {
QRCodeWriter barcodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.QR_CODE, 200, 200);
return MatrixToImageWriter.toBufferedImage(bitMatrix);
}
}
@@ -4,7 +4,6 @@ This module contains articles about Spring Web MVC in Spring Boot projects.
### Relevant Articles:
- [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon)
- [Custom Validation MessageSource in Spring Boot](https://www.baeldung.com/spring-custom-validation-message-source)
- [Display RSS Feed with Spring MVC](https://www.baeldung.com/spring-mvc-rss-feed)
- [A Controller, Service and DAO Example with Spring Boot and JSF](https://www.baeldung.com/jsf-spring-boot-controller-service-dao)
@@ -8,7 +8,6 @@ This module contains articles about administering a Spring Boot runtime
- [Logging HTTP Requests with Spring Boot Actuator HTTP Tracing](https://www.baeldung.com/spring-boot-actuator-http)
- [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging)
- [Spring Boot Embedded Tomcat Logs](https://www.baeldung.com/spring-boot-embedded-tomcat-logs)
- [How to Change the Default Port in Spring Boot](https://www.baeldung.com/spring-boot-change-port)
- [Project Configuration with Spring](https://www.baeldung.com/project-configuration-with-spring)
- [CORS with Spring](https://www.baeldung.com/spring-cors)
- [Spring Log Incoming Requests](https://www.baeldung.com/spring-http-logging)
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-springdoc</artifactId>
<version>0.0.1-SNAPSHOT</version>
@@ -16,11 +17,6 @@
<relativePath>../../parent-boot-2</relativePath>
</parent>
<properties>
<java.version>1.8</java.version>
<springdoc.version>1.2.32</springdoc.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -63,6 +59,11 @@
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
<springdoc.version>1.2.32</springdoc.version>
</properties>
<profiles>
<profile>
<id>integration</id>
@@ -11,9 +11,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [The @ServletComponentScan Annotation in Spring Boot](https://www.baeldung.com/spring-servletcomponentscan)
- [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet)
- [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils)
- [Using Custom Banners in Spring Boot](https://www.baeldung.com/spring-boot-custom-banners)
- [Guide to Internationalization in Spring Boot](https://www.baeldung.com/spring-boot-internationalization)
- [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer)
- [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation)
- [Custom Information in Spring Boot Info Endpoint](https://www.baeldung.com/spring-boot-info-actuator-custom)
- [Testing in Spring Boot](https://www.baeldung.com/spring-boot-testing)
@@ -22,11 +20,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Getting Started with GraphQL and Spring Boot](https://www.baeldung.com/spring-graphql)
- [Guide to Spring Type Conversions](https://www.baeldung.com/spring-type-conversions)
- [An Introduction to Kong](https://www.baeldung.com/kong)
- [Spring Boot: Customize Whitelabel Error Page](https://www.baeldung.com/spring-boot-custom-error-page)
- [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class)
- [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer)
- [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter)
- [Spring Boot Exit Codes](https://www.baeldung.com/spring-boot-exit-codes)
- [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon)
- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks)
- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot)
@@ -1,10 +1,4 @@
#server
server.port=9000
server.servlet-path=/
server.context-path=/
#server.error.whitelabel.enabled=false
#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration
#for Spring Boot 2.0+
#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
server.context-path=/
@@ -33,12 +33,4 @@ logging.level.org.springframework=INFO
servlet.name=dispatcherExample
servlet.mapping=/dispatcherExampleURL
#spring.banner.charset=UTF-8
#spring.banner.location=classpath:banner.txt
#spring.banner.image.location=classpath:banner.gif
#spring.banner.image.width= //TODO
#spring.banner.image.height= //TODO
#spring.banner.image.margin= //TODO
#spring.banner.image.invert= //TODO
contactInfoType=email
@@ -1,14 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
</head>
<body>
<div class="container">
<div class="jumbotron" >
<h1 class="text-center"><i class="fa fa-frown-o"> </i> Sorry, we couldn't find the page you were looking for. </h1>
<p class="text-center"><a class="btn btn-primary" href="/"><i class="fa fa-home"></i>Go Home</a></p>
</div></div>
</body>
</html>
@@ -1,16 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
</head>
<body>
<div class="container">
<div class="jumbotron" >
<h1 class="text-center"><i class="fa fa-frown-o"> </i> Sorry, something went wrong! </h1>
<h2 class="text-center">We're fixing it.</h2>
<p class="text-center"><a class="btn btn-primary" href="/"><i class="fa fa-home"></i>Go Home</a></p>
</div></div>
</body>
</html>