天道酬勤,学无止境

spring-mvc

File Upload using Spring MVC

I am new to Spring MVC though not new to Java and working primary on Struts2 and Wicket as my choice for web development I am trying to do a POC of file upload using spring MVC here is my jsp file <form id="fileuploadForm" action="fileupload" method="POST" enctype="multipart/form-data" > <fieldset> <legend>Upload Fields</legend> <input id="file" type="file" name="file" /> <p><button type="submit">Upload</button></p> </fieldset> </form> and my Controller is @Controller @RequestMapping("FileUpload/fileupload") public class FileUploadController{ public ModelAndView processUpload(@RequestParam

2021-09-24 12:32:51    分类:问答    spring   spring-mvc

Remove default spring boot welcome page

I have a spring boot restful application but if I go to the following URLS: http://localhost:8080 http://localhost:8080/profile I then see some default spring boot JSON like the following: { "_links" : { "customerEntities" : { "href" : "http://localhost:8080/customerEntities{?page,size,sort}", "templated" : true }, "profile" : { "href" : "http://localhost:8080/profile" } } } how can I disable this? I dont want those pages apearing

2021-09-24 09:49:14    分类:问答    java   spring   spring-mvc   spring-boot

'springSecurityFilterChain' threw exception;nested exception is java.lang.IllegalArgumentException: providers list cannot contain null values

While starting a SpringBoot Application I keep on getting below error. Is it related to my SpringWebSecurityConfig file?? Below is the file content. @Configuration public class SpringWebSecurityConfig extends WebSecurityConfigurerAdapter { private AuthenticationProvider authenticationProvider; @Autowired @Qualifier("daoAuthenticationProvider") public void setAuthenticationProvider(AuthenticationProvider authenticationProvider) { this.authenticationProvider = authenticationProvider; } @Bean public PasswordEncoder passwordEncoder() { PasswordEncoder passwordEncoder = new BCryptPasswordEncoder()

2021-09-24 08:27:27    分类:问答    java   spring   spring-mvc   spring-security

使用 TaskExecutor 时插入数据的问题(Issue with data insertion while using TaskExecutor)

问题 在我的 Web 服务应用程序中,我实现了异步任务执行器以在数据库中插入对象。 但是在第一次插入时它会抛出以下异常。 org.springframework.orm.hibernate3.HibernateSystemException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: 第二次刷新 url 时,对象已成功插入到数据库中。 问题在于未插入对象的新请求的第一个实例。 XML文件 <bean id="applicationEventMulticaster" class="org.springframework.context.event.SimpleApplicationEventMulticaster"> <property name="taskExecutor"> <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"></bean> </property> </bean> 我使用了org.springframework.core.task.SimpleAsyncTaskExecutor / org.springframework

2021-09-24 08:00:36    分类:技术分享    java   hibernate   spring-mvc   jpa   spring-data-jpa

How to use Spring SAML code with jks or signed metdata

The IDP only provided .crt file and metadata xml file, and IDP told us there is no password for .crt file, I created jks file with command:keytool -import -alias zoom -trustcacerts -file qa.crt -keystore keystory.jks. Now,I downloaded the spring SAML demo code, and changed the securiyContext.xml as bellow: --------matadata.xml--------------------- <md:EntityDescriptor entityID="gene.com" cacheDuration="PT1440M" ID="dfhGJ7yKW7C3nvicVEN.puf7bSh" xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"> <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <ds:SignedInfo> <ds:CanonicalizationMethod

2021-09-24 07:05:19    分类:问答    java   spring-mvc   saml-2.0   opensaml   spring-security-saml2

如何使用 jpa/spring-boot 正确应用 PrePersist 之类的逻辑(How to properly apply PrePersist like logic using jpa/spring-boot)

问题 我有以下模型的一个非常简单的用例 @Entity @Table(name='Foo') class Foo { @Id String id = UUID.randomUUID() String bar Date foo_updated } 当我看到传入的 json 有效负载具有“bar”的值时,我想将 foo_updated 值设置为 new Date()(即 - 这是包含在 POST 中的新值/补丁更新的一部分/包含和在 PUT 中被证明是不同的) 我希望简单地在这个模型上应用 @PrePersist 注释并添加一个简单的条件,询问“bar”是否有效......但很快意识到我不知道该值是否与数据库中的值“不同” (对于 PATCH/PUT 场景)。 我开始走“添加我自己的 RestController”的道路,并在使用 spring 4 ResponseEntity 方法的过程中应用这个逻辑,但是......我觉得这可能最终需要更多的工作/更多的代码来维护。 由于我是 spring-boot/spring-mvc/jpa 的新手,我很好奇我还有哪些其他选择,以及对于这个看似“简单”的要求,首选方法是什么 谢谢您的帮助! 回答1 我最近遇到了这种方法,它涉及记录加载时的先前状态。 您现在可以在绑定新值后访问先前的状态。 @Entity @Table(name='Foo')

2021-09-24 07:04:40    分类:技术分享    spring   spring-mvc   jpa   spring-boot

如何在没有Spring创建bean的情况下在jsp中获取静态方法值?(How to get static method value in jsp without creation bean in Spring?)

问题 下面的字节到 kb 转换代码的代码是静态返回类型。那么如何在没有创建 bean 的情况下在许多 jsp 中获取值。 public static double bytesToKB(int bytes){ return (double)bytes/1024; } 回答1 这个怎么样? <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> <spring:eval expression="T(com.abc.xyz.YourClassName).bytesToKB(2560)" var="result"></spring:eval> Spring Eval result: <c:out value="${result }"/>

2021-09-24 06:34:58    分类:技术分享    spring   spring-mvc

Why does this spring config file not resolve the mvc:resources element

I cant get past this error. The mvc xsd is correct and validated that the resources element exists. Why does this spring config file not resolve the mvc:resources element SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources' I am using springframework v3.0.2 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www

2021-09-24 06:29:33    分类:问答    spring   spring-mvc

No bean named 'springSecurityFilterChain' available

I am getting error No bean named 'springSecurityFilterChain' available when I don't include spring security configuration my code works fine. This project is created using spring annotation based configuration. When I created project using Maven pom.xml, web.xml, MvcConfiguration automatically gets created. Now I want to implement Spring-security with the same project and configuration. My configuration files are shown below. MvcConfiguration.java @Configuration @ComponentScan(basePackages="com.mywebsite.emusicstore") @EnableWebMvc public class MvcConfiguration extends WebMvcConfigurerAdapter

2021-09-24 05:02:15    分类:问答    java   spring   spring-mvc   model-view-controller   spring-security

Spring Injection not working in different service class

I have class @Service("registrationService") @Transactional public class RegistrationService { @Resource(name="registrationDAO") public RegistrationDAO registrationDAO; In the Controller i can access registrationService and registrationDAO with no problem. I have another class @Service("securityService") public class SecurityService implements UserDetailsService { protected static Logger logger = Logger.getLogger("service"); @Resource(name="registrationDAO") public RegistrationDAO registrationDAO; public String test(){ logger.debug(registrationDAO.findUserByID(1) ); return "Testing"; } Now if

2021-09-24 04:20:08    分类:问答    java   spring-mvc   annotations