Posts

Showing posts with the label spring-boot

Spring can not load CSS

Spring can not load CSS Hello I have a little problem, when i'm starting my Spring boot web app, when i'm going to my localhost it cant load CSS. I figured out that it's happening after adding "@ComponentScan" into Main class. So i tried to remove it and then my whole controllers couldnt load ... Meybe someone know solution to this problem. I've tried for about 3 days to do it and nothing helped. I'm putting a code below. meybe someone could figre it out for me. MAIN.class @SpringBootApplication @EntityScan({"com.estomed.Model"}) @EnableJpaRepositories({"com.estomed.Repository"}) @ComponentScan(basePackages = {"com.estomed"}, useDefaultFilters = true) public class SynchronizesiteApplication { public static void main(String args) { SpringApplication.run(SynchronizesiteApplication.class, args); } } WebConfig.class @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourc...

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...

Spring kafka: failed to send Message to channel payload must not be null

Spring kafka: failed to send Message to channel payload must not be null I have two project microservices with spring boot 1.5.9.RELEASE, the first microservice sends a user to a topic and the second microservice consumes this message, when i send the user it shows the error below in the second microservice Stack trace: org.springframework.messaging.MessageDeliveryException: failed to send Message to channel 'verification-token-in'; nested exception is java.lang.IllegalArgumentException: payload must not be null at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:451) ~[spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:375) ~[spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE] at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.3.13.R...

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...

How can I choose ideal way for pagination in Spring boot?

Image
How can I choose ideal way for pagination in Spring boot? I need your advice for paginations. My table data is very long.Therefor I use pagination and every pag action İ call data from database I have a rest method in spring-boot application. This method could get data from database and everthing is ok. I need pag count(all count of my data/ perPage count). I can find this count from db. I must write two seperate method for allCount and the below method? How can I use ideal way for pagination in Spring boot? @CrossOrigin(maxAge = 3600) @RequestMapping(value = "/payment/all", method = RequestMethod.POST) public List<NotaryPaymentInformationEntity> getAllProduct(@RequestBody PaginationModel pag){ try { System.out.println(pag.getPageno()+ " " + pag.getRecords()); Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } Pageable pageable = new PageRequest(pag.getPage...

Springboot - empty get rest response

Image
Springboot - empty get rest response I am building a simple get rest call from MySQL database, the problem is that it returns an empty object. The call itself is takes in an email (I know this is not the best approach), here is my code: Entity: @Entity public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "user_id") private int id; private String email; private String password; private String firstName; private String userName; private String lastName; private boolean active; @Temporal(TemporalType.DATE) private Date createDate; @Temporal(TemporalType.DATE) private Date updateDate; @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id")) private Collection<Role> roles; // constructor // get and setter } Reposi...

@TransactionalEventListener doesn't works where as @EventListener works like charms for the same context

@TransactionalEventListener doesn't works where as @EventListener works like charms for the same context I'm working in an event-driven design of spring boot application. The code consists of following files: Spring boot: ApplicationEvent File i.e MyBusinessEvent.{java @Data @AllArgsConstructor public class MyBusinessEvent { private String data; } Event Publisher File: MyBusinessService.java @Slf4j @Service public class MyBusinessService { private final ApplicationEventPublisher applicationEventPublisher; @Autowired public MyBusinessService( ApplicationEventPublisher applicationEventPublisher) { this.applicationEventPublisher = applicationEventPublisher; } @Override public void save() { String data = "Testing event data"; MyBusinessEvent event = new MyBusinessEvent(data); applicationEventPublisher.publishEvent(event); } } EventListener : MyBusinessEventListener.java @Slf4j @Component public cla...

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...

Activiti6 use spring-boot-starter-web meet requestMappingHandlerMapping error

Activiti6 use spring-boot-starter-web meet requestMappingHandlerMapping error Update: Some people found add ( exclude = SecurityAutoConfiguration.class ) can skip this ‍ error : exclude = SecurityAutoConfiguration.class error @SpringBootApplication(exclude = SecurityAutoConfiguration.class) public class ActivitiApplication { ... } I am using activiti and spring-boot, and when i mix activiti with spring-boot-starter-basic it is ok. But when i add spring-boot-starter-web in my pom.xml , i meet the following error : pom.xml error Here is my codes : codes https://github.com/cybfly/activiti-demo org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionP...

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...

DateTimeFormatter.ISO_OFFSET_DATE_TIME not working as expected

Image
DateTimeFormatter.ISO_OFFSET_DATE_TIME not working as expected Based on this Java Date Time - OffsetDateTime.format() Examples article and this official documentation for DateTimeFormatter I would expect my OffsetDateTime to be serialized as 2011-12-03T10:15:30+00:00 where the offset the offset is +00:00 since its UTC. 2011-12-03T10:15:30+00:00 +00:00 I cannot manage to get the OffsetDateTime to render with an offset, it always just renders with the 'Z' Zulu. What am I doing wrong? This is Spring Boot 2.0.0.RELEASE, and as you can see in the screenshot I've got the following modules on the class path and registered with the objectMapper, although I don't think that's relative because this issue seems to be directly with the DateTimeFormatter, my object mapper is just using the formatter I am giving it. It does have an affect, because as you can see in the second screenshot when I specify the BASIC_ISO_FORMAT it does produce a a different result. BASIC_ISO_FORMAT ...