Tag: spring

@TestPropertySource和@PropertySource不适用于JUnit

看起来我在Spring 4.1.1中使用Spring Boot 1.2.6.RELEASE做的事情根本不起作用。 我只是想访问应用程序属性并在必要时使用测试覆盖它们(不使用hack手动注入PropertySource) 这不起作用.. @TestPropertySource(properties = {“elastic.index=test_index”}) 这也不是.. @TestPropertySource(locations = “/classpath:document.properties”) 也不是.. @PropertySource(“classpath:/document.properties”) 完整测试案例.. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) @TestPropertySource(properties = {“elastic.index=test_index”}) public class PropertyTests { @Value(“${elastic.index}”) String index; @Configuration @TestPropertySource(properties = {“elastic.index=test_index”}) static class ContextConfiguration { } @Test public void wtf() { assertEquals(“test_index”, index); } } 导致 org.junit.ComparisonFailure: Expected :test_index Actual :${elastic.index} 似乎3.x和4.x之间存在很多相互矛盾的信息,我找不到任何可行的信息。 […]

使用Spring的动态表单更好的方法?

我想知道在使用SpringMVC和Spring表单时是否有更简单/更好的方法来处理动态表单(通过js向dom添加表单项)? 具有Invoice对象的成像具有许多LineItem。 public class Invocie { private List LineItems; public Invoice() { lineItems = ListUtils.lazyList(new ArrayList(), FactoryUtils.instantiateFactory(LineItem.class)); } } 显示属于当前使用的发票的项目 要添加LineItems,我有一些js计算新索引并将其添加到DOM。 删除LineItem时,我当前必须重新编号所有索引,这是我想避免的部分,是否可能?

Spring-MVC 406不可接受而不是JSON响应

我正在尝试使用Spring 3.0.6返回JSON响应,但我得到406响应“Not Acceptable”,其描述为:“此请求标识的资源只能生成具有不可接受的特征的响应”请求“接受”标题()。“ 我知道之前已经提出了一个非常类似的问题 ,但是我无法让它适用于我的项目,尽管进行了许多测试但我不明白我做错了什么。 在我的Maven pom.xml中,我有以下内容: org.codehaus.jackson jackson-mapper-asl 1.8.5 compile org.codehaus.jackson jackson-core-asl 1.8.5 compile 在web.xml中,我引用webmvc-config.xml,日志确认已加载。 mainServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/webmvc-config.xml 1 在webmvc-config.xml中,我有以下内容: 我的控制器是: @Controller public class ClassifiedController { @RequestMapping(value = “/classified/{idClassified}”, headers = “Accept=*/*”, method = RequestMethod.GET) @ResponseBody public final Classified getClassified(@PathVariable final int idClassified) { … 我尝试使用或不使用headers参数,但结果相同。 如果我直接使用Firefox调用URL,请求标头包含以下内容(使用firebug进行检查): Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 如果我使用以下JQuery: $.ajax({ url: ‘/classified/38001’, […]

使用log4j在Java中记录运行时exception

我目前正在使用Tomcat,Spring和JAVA构建应用程序。 我使用Log4J作为我的日志库。 我目前正在将所有内容记录到文本文件中。 我遇到的一个问题是RuntimeExceptions没有记录到任何文件。 我想知道是否有办法记录可能抛出到我的应用程序日志文件的所有RuntimeExceptions 。 如果不是可以让它登录到另一个日志文件? 有没有标准的方法来做到这一点? 如果是这样,在Tomcat中运行应用程序时有一种标准的方法吗? 预先感谢您的帮助!

什么是注释,它们如何真正适用于像Spring这样的框架?

我是Spring的新手,现在我听到很多关于Spring Framework的日子。 我有两组非常具体的问题: 第1集: 一般来说注释是什么? 注释如何专门用于Spring框架? 可以在Spring Framework外部使用注释,还是它们是特定于框架的? 第2集: Spring Framework的哪些模块在工业中被广泛使用? 我认为这是Spring MVC,但为什么它是最常用的模块,如果我正确或正确的话呢? 我是Spring的新手,因此可以随意编辑这些问题以使其更有意义。

找不到当前线程的会话(Spring 3.1.X和Hibernate 4)

我正在尝试使用Spring 3.1和Hibernate 4来设置我的项目。我一直在线学习一些教程。 我得到一个奇怪的错误,根据Spring论坛应该已经修复了Spring 3.1。 春虫追踪器 当我的服务调用getCurrentSession() ,它会抛出以下exception: org.hibernate.HibernateException: **No Session found for current thread**] with root cause org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881) ****编辑:根据Spring Spring 3.1 Documentation for Transactions更新了我的spring-dao.xml。 我尝试用org.apache.commons.dbcp.BasicDataSource交换我的数据源。 我的配置中是否有任何可能导致此问题的属性? **** 这是我的spring-dao.xml: hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect 我的用户bean(User.java) package com.foo.lystra.beans; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; […]

Angular2 / Spring Boot允许PUT上的交叉原点

我的Web应用程序有一点问题:一个连接到spring boot API的angular2应用程序。 我无法从angular2应用程序访问我的请求。 我收到此错误: Failed to load http://localhost:8080/deliveryMan/: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:4200’ is therefore not allowed access. Java代码: @RestController @RequestMapping(value = “/deliveryMan”) @CrossOrigin public class DeliveryManController { @Autowired DeliveryManService deliveryManService; @RequestMapping(value = “/getAllDeliveryMan”, method = RequestMethod.GET) public Iterable getAllDeliveryMan(){ return deliveryManService.findAll(); } @RequestMapping(method = RequestMethod.PUT, consumes = […]

spring使用java 8在WebSphere上运行应用程序时出现exception

在WebSphere 9.0 java 8上运行应用程序时,我收到了几个IllegalStateException , CannotCompileException和LinkageError 。 这是堆栈的错误跟踪: Caused by: java.lang.IllegalStateException: javassist.CannotCompileException: by java.lang.LinkageError: org.springframework.aop.framework.ProxyCreatorSupport at org.springframework.aop.framework.JavassistApplicationContext.(JavassistApplicationContext.java:61) … 114 more Caused by: javassist.CannotCompileException: by java.lang.LinkageError: org.springframework.aop.framework.ProxyCreatorSupport at javassist.ClassPool.toClass(ClassPool.java:1120) at javassist.ClassPool.toClass(ClassPool.java:1063) at javassist.ClassPool.toClass(ClassPool.java:1021) at javassist.CtClass.toClass(CtClass.java:1259) at org.springframework.aop.framework.JavassistApplicationContext.(JavassistApplicationContext.java:59) … 114 more Caused by: java.lang.LinkageError: org.springframework.aop.framework.ProxyCreatorSupport at java.lang.ClassLoader.defineClassImpl(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:346) at java.lang.ClassLoader.defineClass(ClassLoader.java:283) at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) […]

如何将JSON数组作为URL中的参数传递

我要求在Web服务调用中将一些值从移动设备传递到服务器,因此我打算以JSON格式传递所有值,如下所示 { “nameservice”: [ { “id”: 7413, “name”: “ask” }, { “id”: 7414, “name”: “josn” }, { “id”: 7415, “name”: “john” }, { “id”: 7418, “name”: “R&R” } ] } 以下是我的服务电话 @RequestMapping(“/saveName”) @ResponseBody public String saveName(String acc) {jsonObject = new JSONObject(); try { ); System.out.println(acc); jsonObject.accumulate(“result”, “saved “); } catch(Exception e) { e.printStackTrace();jsonObject.accumulate(“result”, “Error Occured […]

如何在Spring Security中使用自定义角色/权限?

在将旧应用程序迁移到spring安全性时,我遇到以下exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘_filterChainProxy’: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘_filterChainList’: Cannot resolve reference to bean ‘_filterSecurityInterceptor’ while setting bean property ‘filters’ with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘_filterSecurityInterceptor’: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: […]