Tag: spring

使用freemarker生成html以在电子邮件中发送,无论如何使用渲染的jsp页面?

使用Spring和java邮件发件人发送电子邮件。 无论如何我可以使用普通的jsp视图和jstl标签 – 我不想学习另一堆标签/语法? 目前我的代码如下所示: StringBuffer content = new StringBuffer(); Configuration configuration = freeMarkerConfigurer.getConfiguration(); String templateName = “vslEmail.ftl”; Map templateVars = new HashMap(); templateVars.put(“firstName”, “john”); templateVars.put(“surname”, “doe”); try { content.append(FreeMarkerTemplateUtils.processTemplateIntoString(configuration.getTemplate(ftlName), tempalteVars)); } catch (Exception e) { // handle } // content.append(“Test data”); sendMime(defaultEmailAddress, subject, content.toString()); 我更愿意引用一个jsp而不是ftl?

如何创建嵌套的json作为HttpPost实体

所以我创建了一个unit testing,将一些参数传递给特定的url。 所以这是我传递一些简单参数的方法: HttpPost request = new HttpPost(server.getURL() + “/report/xxx”); String jsonData = “{\”reportId\”:\”my_report\”,\”name\”:\”my_name\”}”; HttpEntity entJson = new StringEntity(jsonData, “application/json”, “UTF-8”); request.setEntity(entJson); 这工作正常,但我不知道怎么做,当我有这样的嵌套json: { “reportId” : “my_report”, “name” : “my_name”, “subReports” : [ { “id” : 144, “reportId” : “10”, “name” : “my_name10”, }, { “id” : 145, “reportId” : “11”, “name” : “my_name11”, } […]

javagenerics类型参数和对这些类型的操作

在寻找我最近遇到的有趣情况的答案时,我遇到了以下问题: 类型安全,Javagenerics和查询 我写了下面的课(清理了一下) public abstract class BaseDaoImpl extends HibernateDaoSupport implements BaseDao { /** * Finds and Returns a list of persistent objects by a collection of criterions * @param criterions * @return list of persistent objects * @throws DBException */ @SuppressWarnings(“unchecked”) protected List findByCriteria(Collection criterions) throws DBException { try { DetachedCriteria criteria = DetachedCriteria.forClass(T.class); // […]

@Valid没有触发 – Spring MVC 3.2

出于某种原因,它不起作用。 我搜索并尝试了在网上找到的所有解决方案。 没有骰子。 看起来我错过了什么。 我的光束: @Entity @Table(name=”employees”) public class Person { private Integer person_id; private String name; private String name2; private String email; private double phone; private String desc; @Id @Max(value=500) @Column (name=”id”) public Integer getPerson_id() { return person_id; } public void setPerson_id(Integer person_id) { this.person_id = person_id; } @NotNull @NotEmpty @Column (name=”fn”) public String […]

处理Spring中的404错误?

这是我将未映射的请求重定向到404页面的代码 @RequestMapping(“/**”) public ModelAndView redirect() { ModelAndView mv = new ModelAndView(); mv.setViewName(“errorPage”); return mv; } 上面的代码工作正常,但问题是像css和js文件这样的web资源也进入这个重定向方法,并且它没有加载任何文件。 但我已经在我的调度程序servlet中有这个代码,但是spring控制器没有识别这个资源映射。 所以我在请求映射中尝试了一些正则表达式来否定资源url这样的东西 @RequestMapping(“/{^(?!.*resources/**)}**”) public ModelAndView redirect() { ModelAndView mv = new ModelAndView(); mv.setViewName(“errorPage”); return mv; } 但这并没有按预期工作。所以,如果有人能帮助它会很棒:)

Maven / Spring:AopNamespaceUtils NoSuchMethod错误

使用Maven在windows下构建我的项目工作正常,但是当我在Linux下构建它时,我得到一个关于其中一个spring库的NoSuchMethodError 。 我猜这是与跨平台的类加载器差异和我的依赖项中的某个地方有关,我可能有两次相同的类但是windows加载一个而linux加载另一个? 有没有人遇到过这个问题,或者对如何进一步调试此错误有任何建议? nested exception is java.lang.NoSuchMethodError: org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(Lorg/springframework/beans/factory/xml/ParserContext;Lorg/w3c/dom/Element;)V: java.lang.NoSuchMethodError: org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(Lorg/springframework/beans/factory/xml/ParserContext;Lorg/w3c/dom/Element;)V at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser$AopAutoProxyConf Stack Trace Pastie POM.xml Pastie

从文件系统导入eclipse项目,然后在服务器上运行

我想在这个链接上做春季安全教程。 在标题为“运行没有Spring Security的教程应用程序”的部分中 ,我采取了以下步骤(针对当前版本与编写教程时使用的版本之间的差异进行了调整): 1.) I downloaded the latest release of the Spring Security Distribution, 2.) found and unzipped a war file in the dist directory called spring-security-samples-tutorial-3.1.2.RELEASE.war 3.) Renamed the resulting folder spring-security-tutorial 4.) Created a general project in eclipse called spring-security-tutorial 5.) Imported all of the contents of the unzipped spring-security-samples-tutorial-3.1.2.RELEASE.war 6.) Right […]

InjectMocks对象的org.mockito.exceptions.misusing.NotAMockException

我试图模拟一个方法的返回值,但我得到NotAMockException 。 @InjectMocks private MyService myService; @Mock private OtherServiceUsedInMyServiceAsAutowired otherServiceUsedInMyServiceAsAutowired; 在MyService我有一个名为myMethod()的方法,我希望在调用此方法时返回虚拟对象。 doReturn(someDummyObject).when(myService).myMethod(any(), any(), any()); 那时我得到了错误。 我究竟做错了什么? 完整错误: org.mockito.exceptions.misusing.NotAMockException: Argument passed to when() is not a mock! Example of correct stubbing: doThrow(new RuntimeException()).when(mock).someMethod();

使用@Qualifier的@Bean声明不起作用

假设我有一个配置类(JmsQueueConfig,见下文)。 在本课程中,我想为整个应用程序配置多个队列。 对于一个队列,没有问题。 但是,当我添加第二个队列并尝试从服务(MemberService)使用其中一个队列时,Spring-boot告诉我 com.example.notification.application.jms.JmsEventPublisher中构造函数的参数1需要一个bean,但是找到了2个: – queueAccountToNotification:由类路径资源中的方法’queueAccountToNotification’定义[com / example / notification / application / jms / JmsQueueConfig.class] – queueNotificationToAccount:由类路径资源[com / example / notification / application / jms / JmsQueueConfig.class]中的方法’queueNotificationToAccount’定义 行动: 考虑将其中一个bean标记为@Primary,更新使用者以接受多个bean,或使用@Qualifier标识应该使用的bean 这是我的Config-Class: @Configuration @EnableJms @ImportAutoConfiguration(classes = { JmsAutoConfiguration.class, ActiveMQAutoConfiguration.class }) public class JmsQueueConfig { @Value(“${APP_QUEUE_ACCOUNT_TO_NOTIFICATION}”) private String queueAccountToNotificationName; @Value(“${APP_QUEUE_NOTIFICATION_TO_ACCOUNT}”) private String queueNotificationNameToAccount; @Bean @Qualifier(“q1”) public […]

自动assemblySpring 3.2独立应用程序失败

这是我第一次在stackoverflow上找不到解决问题的方法: 我正在尝试创建一个带有基于注释的自动assembly的可执行jar独立应用程序,但我无法获得可运行的jar文件(从Eclipse导出为可运行的JAR文件)来完成它的工作。 它确实直接从Eclipse运行为Java应用程序,而不是通过控制台> java -jar test.jar作为独立应用程序运行。 Exception in thread “main” java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘handler’: Injection of autowired dependen cies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.example.serv ice.UserService com.example.controller.TestHandler.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionEx ception: No […]