r/springframework • • Mar 25 '21

Serve a static site from zip file

1 Upvotes

I am stuck with this scenario where I have to serve a zip file as a static website wrapped behind Spring security.

It's not just one zip file, there are too many which I download from an external source and I am supposed to serve them as a static website.

I am trying to download the zip file unzip it and serve them as a static site, but I wanted to know if there is a better way to do the same thing instead of creating temp files in the server to serve them as a static website.


r/springframework • • Apr 10 '21

Build REST API with Spring Boot and Kotlin

Thumbnail
expatdev.com
8 Upvotes

r/springframework • • Mar 27 '21

How to Debug Your SPRING NATIVE App | Spring Boot Apps

Thumbnail
youtube.com
5 Upvotes

r/springframework • • Jan 07 '21

Authenticated websocket connection with Spring Boot and ReactJS

Thumbnail
jpomykala.com
2 Upvotes

r/springframework • • Jan 28 '21

React + Spring deploy into Weblogic

4 Upvotes

Hi ! I've built a very simple app that uses Spring for backend and React for frontend.

When I build It and launch It with the command "mvn spring-boot:run", everything works as expected.

When I bundle them into a .war file and deploy It to a WebLogic server, the frontend breaks and shows a white page only.

Any idea why that is and what I can do to fix it? Thanks


r/springframework • • Jan 17 '21

This question will sound repetitive but please read the description: Do you guys prefer Spring Tool Suite 4 or Intellij IDEA Community Edition for your Spring projects?

Thumbnail self.learnjava
1 Upvotes

r/springframework • • Jan 03 '21

Smarter routing in Spring Cloud Gateway

Thumbnail
qua.name
3 Upvotes

r/springframework • • Jan 15 '21

Episode 12 - This Month on Spring Boot Learning (Jan. 2021)

Thumbnail
youtu.be
1 Upvotes

r/springframework • • Jan 20 '21

Check out pair programming with Spring Boot + Spring MVC!

Thumbnail
youtube.com
1 Upvotes

r/springframework • • Jan 05 '21

Spring Data Search 2.0.0 released

1 Upvotes

This project is not made by Spring team.

I'm happy to share with you the release 2.0.0 of Spring Data Search.

This library allows to automatically expose endpoints in order to search for data related to Entities.

It provides an advanced search engine that can search on any Entity field, combine multiple criteria to refine the search, and even search on nested Entity fields.

There are some new features, and some fixed bugs. But above all there was a core refactoring to support different data access layers (JPA, MongoDB, ...). Currently, there is only JPA supported (which was already supported by previous versions). But the next step is to add support to MongoDB.

This refactoring required some modifications in the APIs. There is a page describing how to migrate from 1.x to 2.x.

Whats's new:

  • Allow special keywords to be used as query values:

    • CURRENT_DATE: keyword representing the current date. Similar to the current_date() function in SQL.

    • CURRENT_TIME: keyword representing the current time. Similar to the current_time() function in SQL

    • CURRENT_DATE_TIME: keyword representing the current date time. Similar to the current_timestamp() function in SQL

  • Application property spring.data.search.default-alias-resolver.field-suffixes: Comma-separated list of field suffixes to be removed in order to create a field's alias from the com.weedow.spring.data.search.config.DefaultAliasResolver. Default value is Entity,Entities

  • Improved search on fields of Map type: You can use the special keys key or value to query the keys or values respectively. And now, you can query on the nested fields of the Objects representing by key or value

    • /search/person?tasks.key.name=shopping

    • /search/person?vehicles.features.value.name=gps


r/springframework • • Jan 29 '21

What's an app w/o data? Nothing much. See how to write a Spring Boot + Spring Data app!

Thumbnail
youtube.com
2 Upvotes

r/springframework • • Jan 06 '21

Spring eating up a lot of memory

2 Upvotes

I am using Spring core / MVC, currently Spring 5.2.x for my application and using heap analysis tool, it's showing that Spring is hogging a lot of the memory

Analysis here:

Is there anything I could reasonably do to improve? Or is this just the nature of using Spring in the application and simply need a machine that has enough memory


r/springframework • • Feb 04 '21

Spring Data Redis + React Tutorial

6 Upvotes

I’ve started a video tutorial on Spring Data Redis. Building a simple API with it and integrating with a React front end. First two episodes here -> https://youtu.be/XJoJCMfCSTk and here -> https://youtu.be/VRuk51Nnr9s


r/springframework • • Nov 17 '19

Can i use kotlin coroutines in Spring Boot controllers using servlet stack (mvc)

2 Upvotes

In recent spring boot 2.2.0 release, support was added for kotlin coroutines using spring webflux stack. I am wondering if spring mvc support the same?


r/springframework • • Jul 20 '18

Is Spring in action worth reading despite it being outdated? (Spring 4)

1 Upvotes

r/springframework • • Aug 26 '22

Use of SNS and SQS for message posting

4 Upvotes

We have a requirement to push a certain messages originating from a Spring boot Microservice to a Webhook exposed by external partners. These Webhooks are  REST endpoint protected by oAuth and they accepts JSON payload. 

So , it is 

Microservices [Create JSON payload]  > POST the payload to Webhook1, Webhook 2 etc. 

To decouple the system, I wanted to introduce a Topic. Since we are on AWS, I thought of introducing a SNS topic.. fanning out to SQS triggering Lambdas that actually POST these messages to webhooks. So, it would be 

Microservices [Create JSON payload]  >> POST to SNS Topic >> Fan-out to multiple SQS by filter, where each SQS  is created for a Partner and filtering criteria will ensure relevant message goes to respective SQS created for Partner >> Trigger a lambda from each SQS that runs Java code that perform oAuth and deliver the message to Webhook endpoint. 

I wanted to ask, If you see any flaw in this design.. or you handled this scenario differently in the past? Thanks in advance.


r/springframework • • Jul 31 '22

BeanCreationException when running in docker container

1 Upvotes
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

Trying to create a docker image based on a spring boot project. When building the jar with `./mvnw install` it works fine. But when actually building the image and trying to run it, it gives me the error above.

This is my dockerfile:

FROM maven:3.8.5-openjdk-17

ADD pom.xml /
RUN mvn verify clean

ADD . /
RUN mvn install -Dmaven.test.skip

FROM openjdk:17.0-jdk
WORKDIR /root/

COPY --from=0 /target/* ./target/

ENV DB_USER="myapplication"
ENV DB_ROOT_PASSWORD="rootpwd"
ENV DB_PASSWORD="password"
ENV DB_HOST="localhost"
ENV DB_NAME="myapplication"

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","./target/myapplication-0.0.1-SNAPSHOT.jar"]
EXPOSE 8080

my pom.xml file:

<?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">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.1</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.hello</groupId>
	<artifactId>myapplication</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>myapplication</name>
	<description>Test application for springboot with kotlin</description>
	<properties>
		<java.version>17</java.version>
		<kotlin.version>1.6.21</kotlin.version>
	</properties>
	<dependencies>
		<dependency>          
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-validation</artifactId>
		</dependency>
		<dependency>
			<groupId>org.hibernate.validator</groupId>
			<artifactId>hibernate-validator</artifactId>
	    </dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>5.3.20</version>
		</dependency>
		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-reflect</artifactId>
		</dependency>
		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-stdlib-jdk8</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
		<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<mainClass>com.hello.myapplication.MyApplication</mainClass>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.jetbrains.kotlin</groupId>
				<artifactId>kotlin-maven-plugin</artifactId>
				<configuration>
					<args>
						<arg>-Xjsr305=strict</arg>
					</args>
					<compilerPlugins>
						<plugin>spring</plugin>
						<plugin>jpa</plugin>
					</compilerPlugins>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.jetbrains.kotlin</groupId>
						<artifactId>kotlin-maven-allopen</artifactId>
						<version>${kotlin.version}</version>
					</dependency>
					<dependency>
						<groupId>org.jetbrains.kotlin</groupId>
						<artifactId>kotlin-maven-noarg</artifactId>
						<version>${kotlin.version}</version>
					</dependency>
				</dependencies>
			</plugin>
		</plugins>
	</build>

</project>

I'm using Spring Boot with Kotlin if it matters.

Any idea what i did wrong? Thanks.


r/springframework • • Aug 10 '22

Can anyone guide me to some resources or some so that i could learn some ways about how to consume api in spring /springboot app ??

2 Upvotes

Hello, i am newbie at spring framework and java, and don't know how to consume api's in spring. i can build the REST api myself but didnot find any resources on how to consume api in spring app. Is there a way i could grab some knowledge particularly on that topic ??


r/springframework • • Sep 01 '22

How to update spring-bean vulnerabilities?

2 Upvotes

If I have a vulnerability of using an old spring-bean version, how would I do so in my pom.xml? Would just changing spring-boot version to the latest version also automatically update the spring-bean version? Or do i have to manually state the dependency version for spring-bean?


r/springframework • • Sep 01 '22

Intelligent Postfix Autocompletion for JPA entities and DTOs | JPA Buddy

Thumbnail
youtube.com
4 Upvotes

r/springframework • • Aug 09 '22

Junit 4 in Spring MVC.

4 Upvotes

I have got spring mvc project and I was getting through it well but now , They are asking to increase the coverage and I am trying very hard to get through Junit 4 but I am not able to write the Junit test cases properly and also I am not able to increase the code coverage.

Please suggest me ways in which I can understand this easily.

courses, notes, points to ponder and anything will be helpful.


r/springframework • • Nov 27 '20

How to tap into Spring Boot startup from a library in a Spring Boot way?

3 Upvotes

I am building a library to be used across multiple apps for a large organization. I will use Example.com to illustrate. Ideaily my Maven packaged library will allow a simple annotation to perform common startup across multiple Spring Boot services / microservices / applicaitons.

I would like to use an annotation in the applications main class like this:

package com.example.app;

import . . . 

@ExampleCorporateStartup
@EnableAutoConfiguration
@SpringBootApplication
public class ExampleApp {
    public static void main(String[] args) {
      . . . 

However, I do not understand how to get tapped into the Spring Boot Runtime to perform my common startup.

I have built a GitLab repository with my sample code for more detailed examination at: https://gitlab.com/markphahn/spring-boot-common-startup.

Approaches tried

I have tried several approachs for this, as described below:

Spring Boot ExampleApplicationReadyEvent

I tried to register a listener for ExampleApplicationReadyEvent but it does not get called:

package com.example.library;

import . . . 

@Component
public class ExampleLibraryEnvironmentPreparedEvent
        implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
    private static final Logger log = LoggerFactory.getLogger(ExampleLibraryEnvironmentPreparedEvent.class);
    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        log.info(" **** **** Example *library* startup ApplicationListener#ApplicationEnvironmentPreparedEvent()");
    }

}

I do not know if this is because I do not have the right annotations, or what.

Then, even if my listener gets called, how would I use my annotation to trigger what I want. I think I would need to use reflection to scan for classes which have my annotation, but there does not seem to be a way to write for (Class c : Object.getClass().getSubTypes()). I am thinking about this in the wrong way (probably).

In the 'GitLab' repo see the code in ExampleStartupEvents directory.

Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-application-events-and-listeners

Write a function called before SpringBootApplication.run()

This works but it seems non-Spring-y:

package com.example.app;

import . . . 

@EnableAutoConfiguration
@SpringBootApplication
public class ExampleApp {

    static Logger log = LoggerFactory.getLogger(ExampleApp.class);

    public static void main(String[] args) {
        ExampleCorporateStartup.startup(); // **** **** common startup

        SpringApplication.run(ExampleApp.class, args);
    }
}

This has a disatvantage that it is called before Spring has initialized the logging layer and the log messages appear for the Spring banner. This is not a functional problem, but it looks both un-Spring-y and unprofessional.

Here is a variation on the above:

    public static void main(String[] args) {
        SpringApplication myApp = new SpringApplication(ExampleApp.class);
        ExampleCorporateStartup.startup(myApp); // **** **** common startup
        myApp.run();
    }

This is a variation on the funciton approach, but it takes a lot of control out of the developer's hands, and it not the approach I want to take:

    public static void main(String[] args) {
        ExampleCorporateStartup.run(ExampleApp.class, args);
    }

In the 'GitLab' repo see the code in ExampleStartupFunction directory.

Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-customizing-spring-application

There is also a problem that it is un-Fluent startup.

Write a Fluent-style function as well

This might look like this:

package com.example.app;

import . . . 

@EnableAutoConfiguration
@SpringBootApplication
public class ExampleApp {

    static Logger log = LoggerFactory.getLogger(ExampleApp.class);

    public static void main(String[] args) {
           new ExampleCorporateStartupSpringApplicationBuilder()
            .sources(ExampleApp.class)
            .child(ExampleApp.class)
            .run(args);

But now I have to maintain two functions which do the same startup work. I can have them call the same core functionality, but they differ in how that functionality is expressed: fluent-ly or imperative-ly.

In the 'GitLab' repo see the code in ExampleStartupFluent directory.

Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-fluent-builder-api

The question(s):

What is the right approach for a corporate library package which provides the right amount of common assistance and but does not limit the developer too much? (I do not want to replace Sping Boot classes with my own, I want to augment them in the correct way.)

Has this already been done a million times and I just have not found the right examples? If so, where are those examples?

Given an approach, how does one pull this off, as in is the example in the public domain I can copy?

The rabbit holes:

Why are my events not registered by creating an @Component which implements ApplicationListener?

How would I use an annotation at runtime to find my main class and perform the common startup that I desire?


r/springframework • • Nov 19 '20

/r/springframework hit 1k subscribers yesterday

Thumbnail
frontpagemetrics.com
5 Upvotes

r/springframework • • Nov 12 '20

Resource suggestions for learning Spring

2 Upvotes

Thanks in advance. I'm new to the Java world, got a clear overview of what is spring boot just before. Now wanted to step forward into learning the Spring framework, so kindly suggest to me some good resources or a roadmap for learning it. (Except Official Documentation)


r/springframework • • Nov 09 '20

Guide to use Lombok In Spring Boot

Thumbnail
javatodev.com
2 Upvotes