Posts

Showing posts with the label spring

Spring webFlux infinite recursion

Spring webFlux infinite recursion So I'am trying Spring webFlux and have following code: @Override public Flux<? extends AnimalDatabaseEntity> queryAnimals() { return async(animalsRepository.findAll().stream()); } private <T> Flux<T> async(Stream<T> stream) { return Flux.fromStream(stream).publishOn(scheduler); } The problem that I get infinite recursion, because " AnimalDatabaseEntity " has field animalFeatures . @Entity(name = "animals") public class AnimalDatabaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "name") private String name; @Enumerated(EnumType.STRING) @Column(name = "animal_type") private AnimalType animalType; @Column(name = "number_of_legs") private Integer numberOfLegs; @Column(name = "is_pet") private boolean isPet; @OneToMany(mappedBy = "animalDatabaseEntity", fetch = FetchT...

jhipster keycloak integration always redirect to localhost:8080

jhipster keycloak integration always redirect to localhost:8080 Angular/Spring app generated using jhipster here's my app configs " application.yml " Angular/Spring application.yml security: oauth2: client: access-token-uri: http://test.com:9080/auth/realms/urms/protocol/openid-connect/token user-authorization-uri: http://test.com:9080/auth/realms/urms/protocol/openid-connect/auth client-id: urms client-secret: urms client-authentication-scheme: form scope: openid profile email resource: user-info-uri: http://test.com:9080/auth/realms/urms/protocol/openid-connect/userinfo token-info-uri: http://example.com:9080/auth/realms/urms/protocol/openid-connect/token/introspect prefer-token-info: false I deployed the application to my domain let's say "test.com" server. Problem Once user go to " /login " he will reach keycloak with redirection URL like /login http://test.com:908...

How to import spring xml basis on condition

How to import spring xml basis on condition Is there any way to import to load the spring configuration file to another by placing some conditional value, which is taken from the .properties file <import resource="classpath:META-INF/spring/MandatoryConfigForThisService.xml" /> desired solution want to be like the following: <import condition="${isEnabled}" resource="classpath:META-INF/spring/MandatoryConfigForThisService.xml" /> By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Spring Boot Application immediately shuts down after starting in external TOMCAT

Spring Boot Application immediately shuts down after starting in external TOMCAT Spring boot immediately shuts down after starting in external TOMCAT. But in Eclipse this runs well and JAR with embed too. I use Tomcat 7 and JAVA 8. I read a lot of webs and documentation which do not exist. My Eclipse POM is: http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 <groupId>com.suez.demo</groupId> <artifactId>Myapp</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>Myappname</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <proje...

The generated tests(producer side) failed in Spring Cloud contract and AMQP/RabbitMQ

The generated tests(producer side) failed in Spring Cloud contract and AMQP/RabbitMQ I was trying to use AMQP/RabbitMQ and Spring cloud contract in my microservice projects to define the contract between producers and consumers. I am using the last Spring Boot 2.0.3, and Spring Cloud Contract 2.0.0. I have prepared a sample project to reproduce the problem. In the producer side , I created a base test class: @SpringBootTest(properties = "stubrunner.amqp.enabled=true") @RunWith(SpringRunner.class) @AutoConfigureMessageVerifier public class MessageVerifierBase { @Autowired MessageVerifier verifier; @Autowired Sender sender; public void send() { this.sender.send(Notification.builder().body("test message").build()); } @Before public void setup() { verifier.receive("notification.exchange", 100, TimeUnit.MILLISECONDS); } } The Sender just called RabbitTemplate . Sender RabbitTemplate @Component public clas...

Did the contextPath is available as a placeHolder for defining the path of a properties files

Did the contextPath is available as a placeHolder for defining the path of a properties files Let start with some context: I use something like this for properties: <bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="ignoreResourceNotFound" value="true"/> <property name="locations"> <list> <value>classpath:internal-common.properties</value> <value>classpath:${server.contextPath}/context.properties</value> <value>classpath:dev-overwrite.properties</value> </list> </property> The internal-common and the dev-overwrite work as expected. I can't found the correct placeHolder (not ${server.contextPath} at least) to have an external properties per context. What I think can't work and are on lot of answer related to this: ...

Static resource mapping in Spring3

Static resource mapping in Spring3 My project is implemented in Spring3 and configuration is almost xml. Configuration of static resource mapping is like below: <mvc:resources mapping="/a/**" location="file:/data/a/"/> There is no problem when accessing /a/xxx.jpg but 404 Error is occurred when accessing subdirectory like /a/b/yyy.jpg. There is no problem about access authority of filesystem. How can I solve this problem? Additional configuration is needed? (Add) Project directory is fine, but filesystem directory does not work 1 Answer 1 Use something like below : <mvc:resources location="/" mapping="/resources/**"/> You can specify classpath also to location any particular folder like below. <mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/> Project direc...

request.getRequestURI always returns “/error”

request.getRequestURI always returns “/error” In a webapp I'm building using Spring Boot & MVC and am trying to deny access to for all URL's except /signin for users that are not logged in. To achieve this I've setup an implementation of HandlerInterceptor where the preHandler should route all non-valid requests to the /signin page. The setup: LoginViewController package com.controller; import com.model.UserDao; import com.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @Controller @RequestMapping(value = "/signin") @SessionAttributes("username...

Spring WS is generating empty SOAP Envelop

Spring WS is generating empty SOAP Envelop I want do call a SOAP service with Spring WS WebServiceTemplate. I have used this very often and it always worked so far. But now I just get an soap envelope with empty body: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body/></SOAP-ENV:Envelope> I have created the request and response classes with the JAXB Maven Plugin. And the generated source code looks exactly like the services which are working. Example: @XmlAccessorType(XmlAccessType.FIELD) @XmlType( name = "startRequest_RequestParameters", propOrder = {"url"} ) @XmlRootElement( name = "startRequest" ) public class StartRequest { @XmlElement( required = true ) @XmlSchemaType( name = "anyURI" ) protected String url; public StartRequest() { } public String getUrl() { return this.url; } public void setUrl(String valu...

Use system variable in spring boot [duplicate]

Use system variable in spring boot [duplicate] This question already has an answer here: I have defined a variable in my .bash_profile like this : export PROFILE=local Now, I want to get this value in my spring boot application to load different configuration files according to this value. To do this, I used the annotation @Value but spring can't resolve the value of profile : @Value("${profile}") private String environment; What have I missed ? EDIT : This code is launched from a JUnit test inside Eclipse (launched as desktop application) This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. did you try ${PROFILE} – pvpkiran 2 days ago ${PROFILE} Yes and it doesn't work ! – midix ...

Keycloak: Spring Boot project as bearer and reusing token from user

Keycloak: Spring Boot project as bearer and reusing token from user I am building an application with an angular frontend and spring boot on the backend. I was able to configure the angular and spring part. So, the frontend requests a token and sends it with every request to the java backend. This works just fine. My java backend is now in the need to reuse the client token to request data from another service, which uses the same mechanism. What is the right way to go forward? Requesting an own token for my service or using the existing token from the authenticated user? I have not found a way to do this. While calling your 3rd service you can use the same token , Add your third service as bearer-only Client. – ravthiru 2 days ago By clicking "Post Your Answer", ...

WebApplicationContext does not Autowire when injecting in Spock Specification

WebApplicationContext does not Autowire when injecting in Spock Specification Although I followed the Spring Boot Guide, when trying: @SpringApplicationConfiguration(classes=MainWebApplication.class, initializers = ConfigFileApplicationContextInitializer.class) @WebAppConfiguration @ActiveProfiles("integration-test") class FirstSpec extends Specification{ @Autowired WebApplicationContext webApplicationContext @Shared MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build() def "Root returns 200 - OK"(){ when: response = mockMvc.perform(get("/")) then: response.andExpect(status().isOk()) } } I just get the message that a WebApplicationContext just is not injected. I do have <dependency> <groupId>org.spockframework</groupId> <artifactId>spock-spring</artifactId> </dependency> <dependency> <groupId>org.spockframewo...

How to start specific spring batch job with command line

How to start specific spring batch job with command line I have two configured jobs in my spring boot application. I want to trigger a job manually, using a command in my docker-compose.yml to trigger it. To accomplish this first I disable the batch.job.enabled property in my application.yml: batch: initialize-schema: always job: enabled: false I disable it in order to not allow Spring to execute my jobs on application startup. I'm trying to test my jobs with docker, so in my docker-compose.yml I set this command on my application service to execute when my container is up: command: java -jar batch-application-1.0-SNAPSHOT.jar -Dspring.batch.job.names=uploadToS3Job date=2018-06-26 type=MyType This command runs the uploadToS3Job with job parameters date and type. uploadToS3Job When I run my application with docker-compose up --build , spring application runs smoothly but the job is not executed, nothing happens, no crash, no nothing. docker-compose up --build But if I s...