JAVASPRING - 技术教程文章

Java-Spring Security-禁用注销重定向【代码】

我正在使用带有REST的Spring Security,并且正在使用URL(/ logout)作为我的注销方法的端点.但是在调用此方法后,它将我重定向到(/ login?logout),我知道这是春季logOutSuccessUrl.我想摆脱重定向.这是我的代码:protected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/login").permitAll().anyRequest().fullyAuthenticated().and().requiresChannel().anyRequest().requiresSecur...

Java-SpringMVC-获取控制器中的参数【代码】

我无法将对象持久保存到数据库中.我有一个用户与Profil具有多对一关系. 我的JSP只需添加一个新用户.因此,JSP包含字段和带有所需概要文件的comboxBox.问题是,当我运行程序时,即使我在comboxBox中选择了一个配置文件,该属性user.profil在控制器中也为NULL. 这是User对象:package com.app.model;import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence...

java-Spring记住我,带有额外的登录参数【代码】

在spring mvc应用程序中,我在登录屏幕上捕获了一个附加的“位置”参数,除了用户名外,还将其用于身份验证.所以在“ loadUserByUsername”中,我的sql查询是这样的,select from user where username = ? and location = ? 现在,如果用户是我的“记住我”用户,则因为没有登录提示,所以无法捕获“位置”参数.如果使用“记住我”功能,spring只会在Cookie中存储用户名.对于“记住我”登录,它随后从cookie中检索该用户名,并将其传递给“ lo...

java-Spring MVC转换如何【代码】

我的车辆服务包括零件清单.添加新服务不是问题,查看服务也不是问题,但是当我尝试实现编辑时,它不会预先选择零件列表.因此,考虑到这是Thymeleaf的问题,我发布了问题here. 我得到的答案是尝试实现spring转换服务.我只是这样做了(我认为),现在我需要帮助才能摆脱困境.问题在于,视图将服务中的零件实例与包含所有零件的partsAttribute零件形式的实例进行比较,并且从不使用转换器,因此它不起作用.我没有收到任何错误…在视图中,未选择零...

java-Spring RESTful客户端:根标签异常【代码】

我正在尝试在此示例http://thekspace.com/home/component/content/article/57-restful-clients-in-spring-3.html之后使用RestTemplate解析RESTFull调用的结果 XML响应是这样的:<brands><brand><nodeRef>1111111</nodeRef><name>Test</name></brand> </brands>首先,我像这样配置了application-context.xml:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://...

java-Spring Rest-产生Json数据的异常【代码】

这个问题已经在这里有了答案: > Strange Jackson exception being thrown when serializing Hibernate object 15个我有一个要通过json rest调用公开的value对象.在我的项目中,我还有许多其他的休息电话都可以正常工作,但是由于某种原因,这个1不能正常工作.当我尝试将该对象返回时-我收到一个异常,我不知道该如何解决 值对象代码如下(减去访问器方法)package com.test.d...

java-Spring数据JPA只有一个组合键是自动递增的问题【代码】

我正在使用MySQL数据库. 在我的表中,有两个四个主键,其中一个是自动递增的.@Embeddablepublic class EmployeeId implements Serializable {/*** */private static final long serialVersionUID = 1L;@Column(name = "id", nullable = false)// This is just Pk in mysql table**private int id;**// I have tried and @GeneratedValue(strategy = GenerationType.IDENTITY),@GeneratedValue(strategy = GenerationType.IDENTITY)...

友好的网址映射问题-Java Spring【代码】

我在web.xml上的所有页面都都显示为404的错误中挣扎,可能存在根路径,但是我不确定其设置位置等. 这是我当前的web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/java...

java-Spring JPA:没有事务正在进行【代码】

我在将我的Spring应用程序中的实体持久化时遇到问题.仅执行em.merge()即可完成但没有错误,但不会更新数据库,而尝试em.flush()会导致此异常:2015-12-19 18:01:40 DEBUG DispatcherServlet:976 – Could not completerequest org.springframework.dao.InvalidDataAccessApiUsageException: notransaction is in progress; nested exception isjavax.persistence.TransactionRequiredException: no transaction is inprogress这是我的...

java-Spring Boot外部配置和xml上下文【代码】

我想通过Spring Boot外部化我的配置,但我想继续部分使用xml上下文. 我的主类SpringServerApplication.java:@Configuration @PropertySources(value = {@PropertySource("classpath:/application.properties")}) public class SpringServerApplication {public static void main(String[] args) throws Exception {SpringApplication.run(new Object[] {SpringServerApplication.class, "classpath:ApplicationContextServer.xml" ...

Javaspring+mybit+maven中实现定时任务【图】

背景:在Javaspring中,定时的启动某一个任务时,使用@Scheduled来实现 Javaspring工程创建好之后,直接创建下面的class文件即可。具体的用法可参照 https://www.cnblogs.com/yanfei1819/p/11076555.html#4286355 https://www.cnblogs.com/JonaLin/p/11125966.htmlpackage com.cnc.mht.necmst.mstobtain; import java.util.Date; import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereoty...

Javaspring+mybit+maven中实现Junit测试类

在一个Javaspring+mybit+maven框架中,增加Junit测试类。 系统:window7 1.首先在配置文件pom.xml文件中添加测试类的包文件,之后执行maven取得相对应的包文件到本地     <dependency><!-- JUnit单元测试框架 --> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency><!-- spring对测试框架的简单封装功能 --> <groupId>org.springframew...

Java Spring多个ApplicationContext【代码】

SpringContextContext的定义非常模糊,我几乎完成了整本教程,但仍然无法理解ApplicationContext代表什么. 根据Spring API,ApplicationContext是:Central interface to provide configuration for an application. This is read-only while the application is running, but may be reloaded ifthe implementation supports this.The root interface for accessing a Spring bean container. This is the basic client view of a be...

Java Spring resttemplate字符编码【代码】

我正在使用Java Spring Resttemplate通过get请求获取json.我得到的JSON不是特殊字符,而是some或一些奇怪的东西.所以我猜这个字符编码有些不对劲.我在互联网上找不到任何帮助.我现在使用的代码是:String json = restTemplate.getForObject(overPassStatementPostCode,String.class,params);解决方法:您只需要将StringHttpMessageConverter添加到模板的消息转换器:RestTemplate template = new RestTemplate(); template.getMessag...

使用REST模板Java Spring MVC从服务器下载大文件【代码】

我有一个REST服务,它向我发送一个大的ISO文件,REST服务中没有问题.现在我已经编写了一个Web应用程序,它调用其余服务来获取文件,在客户端(Web应用程序)端我收到Out Of memory Exception.Below是我的代码HttpHeaders headers = new HttpHeaders();//1 Lineheaders.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));//2 Lineheaders.set("Content-Type","application/json");//3 Lineheaders.set("Cookie", "session=ab...

java spring context:property-placeholder手动加载【代码】

Spring java- quartz schedular应用程序 我想加载.property文件动态传递throw程序参数而不是context:property-placeholder在spring上下文中,我该如何实现这个任务,任何帮助都赞赏… 我从主java文件手动加载和刷新spring上下文,如下面的代码所示.SpringUtil_1.loadSpringConfig(); rootContext = new ClassPathXmlApplicationContext(); rootContext.setConfigLocation("abc-configuration.xml"); rootContext.refresh();在spring配...

Java Spring Patch RFC-6902即时类型转换异常【代码】

我有修补问题,这与将String值转换为相应的类型有关.当我尝试修补“Locale”类型(或原语)时,它可以工作.但它失败了即时 实体:@JsonIgnore @Field("locale") private Locale locale;@JsonIgnore @Field("dateOfBirth") private Instant dateOfBirth;@JsonIgnore public Locale getLocale() {return this.locale; }@JsonIgnore public void setLocale(Locale locale) {this.locale = locale; }@JsonIgnore public Instant getDateOfB...

Java Spring:AnnotationSessionFactoryBean,Hibernate-Dialect AutoDetection【代码】

我使用以下spring应用程序上下文:<!-- Hibernate session factory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="hibernateProperties"><props><!--<prop key="hibernate.dialect">${hibernate.dialect}</prop>--><prop key="hibernate.show_sql">${hibernate.show_sql}</prop><prop key="...

Java Spring Batch与Apache Spark基准测试中的ETL

我已经使用Apache Spark Scala超过5年了(学术和专业经验).我总是发现Spark / Scala是用于构建任何类型的批处理或流式ETL / ELT应用程序的强大组合之一. 但最近,我的客户决定在我们的两个主要管道中使用Java Spring Batch: >从MongoDB中读取 – >业务逻辑 – >写入JSON文件(~2GB | 600k行)>阅读Cassandra – >业务逻辑 – >写JSON文件(~4GB | 2M行) 这个企业级决策令我感到非常困惑.我同意业内有更多的思想,但我无法理解采取这一行...

JAVA Spring MVC 物料清单BOM 展开实例【代码】【图】

相关概念:BOM 展开、LIST对象、JSON 字符串、JSON 对象 最近在开发一个管理软件,涉及到物料清单(又称产品结构)BOM管理的相关内容,其中之一就是BOM 的展开。BOM的展开一般有纵向优先展开、层次优先展开和汇总展开等形式,也有很多展开的算法。在开发中使用Spring MVC 框架完成了BOM按层级优先展开的程序,也涉及到了JAVA开发中的相关知识如LIST 对象、LIST 对象转JSON 串,JSON 串返回前端并还原成JSON 对象,在前端通过JSON ...

java spring获取请求ip地址【代码】

洒家的需求是 想根据客户端的请求获取ip地址,然后对ip请求加次数限制,客户端请求首先负载均衡(F5)转发到网关(Zuul),网关接收到请求后,从注册中心(Eureka)获取可用服务,在服务端获取请求的ip。 直接上方法: public static String getIpAddress(HttpServletRequest request) {String ip = request.getHeader("x-forwarded-for");if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {ip = request.g...

Java Spring MVC:没有为带HTTP的HTTP请求找到映射【代码】

我在设置Spring MVC时遇到了问题……我有这个项目结构-SpringTest<br />-Java Resources-src-org.basic.controllerFormController.java . . . . -WebContent+META-INF-WEB-INFdispatcher-servlet.xml+lib-viewsform.jspweb.xml这些是代码页: web.xml中<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.su...

Java Spring表单标记问题【代码】

我正在使用JSP,这是我的contacts.jsp<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <html> <head><title>Spring 3.0 MVC series: Contact manager</title> </head> <body> <h2>Contact Manager</h2> <form:form method="post" action="addContact.html"><table><tr><td><form:label path="firstName">First Name</form:label></td> // LABEL<td><form:input path="firstName" /></td></tr><tr><td><...

Java Spring应用程序的插件

假设我有一个基于Java Spring的客户端应用程序,它向服务器发送请求并处理响应.它使用命令模式进行响应处理. 现在我想在运行时发现并加载这些命令.你会如何实现它? 我知道“插件”技术,例如JPF和OSGI,但它们对我来说看起来很大.我正在考虑使用Spring的自动装配.你会推荐吗?解决方法:如果您正在寻找一个非常漂亮,轻巧且功能强大的插件框架,请查看Java Simple Plugin Framework.我已经广泛使用它并且它工作得很好. 使用Spring的自动...

java springboot 主从多数据源【代码】【图】

yum配置 # 数据源配置 spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriverClassName: com.mysql.cj.jdbc.Driverdruid:# 主库数据源master:url: jdbc:mysql://120.78.127.53:3306/zipkin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8username: rootpassword: 123456# 从库数据源slave:# 从数据源开关/默认关闭enabled: trueurl: jdbc:mysql...

Java Spring JDBC模板问题【代码】

public List<Weather> getWeather(int cityId, int days) {logger.info("days: " + days);return getSimpleJdbcTemplate().query("SELECT weather.id, cities.name, weather.date, weather.degree " +"FROM weather JOIN cities ON weather.city_id = cities.id " +"WHERE weather.city_id = ? AND weather.date BETWEEN now()::date AND (now() + '? days')::date",this.w_mapper, cityId, days); }错误:org.springframework.web...

如何在Java Spring MVC应用程序中读取属性(或任何其他文本)文件?【代码】

我需要在我的Spring MVC应用程序中读取java属性文件,但我找不到这样做的方法.我在这里尝试了类似问题的几个答案,但我没有成功.我是Java新手,尤其是Spring MVC,所以我可能搞砸了. 我不确定该文件是否已成功部署.我正在使用Tomcat btw.解决方法:如果您使用的是Spring 3.1,则可以使用@PropertySource注释:@Configuration @PropertySource("classpath:/com/example/app.properties") public class AppConfig {// create beans }或者对...

基于java spring的webserver的Android websocket sockjs客户端【代码】

我正在使用Spring 4.1.6.RELEASE和我的服务器配置为使用基于SockJs和STOMP协议的websocket方法从这里http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html,这里我在服务器端的简单xml配置:<websocket:message-broker application-destination-prefix="/app"><websocket:stomp-endpoint path="/hello" allowed-origins="*"><websocket:sockjs/></websocket:stomp-endpoint><websocket:simpl...

如何将Java Spring time属性绑定到Thymeleaf字段?【代码】

我有一个Java时间属性绑定到Thymeleaf字段的问题. 这是我的HTML代码<input th:field="*{startTime}" type="text"/> <script>$("#startTime").timepicker({showSeconds: true,showMeridian: false,secondStep: 1}); </script>这是我的模型属性代码@NotNull(message = "Start time cannot be empty") private Time startTime;public Time getStartTime() {return startTime; }public void setStartTime(Time startTime) {this.startT...

Java Spring REST API CORS不适用于通过jQuery与Chrome的DELETE请求【代码】

我正在创建一个使用jQuery编写的Web前端,它使用Spring框架将REST请求发送到用Java编写的REST Web服务.我在CORS请求中遇到了一个奇怪的错误.特别是,如果我使用Safari,一切正常;相反,使用Chrome,所有DELETE请求都失败(GET和POST请求在Chrome中也能正常工作). 我得到的错误是:Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. O...