我有一个应用程序,其中使用属性占位符来读取属性,配置在applicationContext.xml:
...
<context:property-placeholder
location="classpath*:META-INF/spring/*.properties"/>
...
Run Code Online (Sandbox Code Playgroud)
应用程序在Tomcat中运行,并使用context.xml中定义的参数.应用程序像普通属性(@Value(${cfma.applicationUrl}))一样访问此参数.这有效
在我的测试用例中,我没有这个tomcat属性,所以我想将它们"手动"添加到应用程序上下文中.但也加载正常applicationContext.xml
testContext.xml:
<import resource="classpath:/META-INF/spring/applicationContext.xml" />
<context:property-placeholder properties-ref="simulatedTomcatProperties"/>
<util:properties id="simulatedTomcatProperties">
<prop key="cfmt.applicationBaseUrl">localhost:8080/cfmt</prop>
</util:properties>
Run Code Online (Sandbox Code Playgroud)
现在我有两个上下文:属性占位符,这不起作用(当然) - 所以我的问题是,我可以在测试中的"普通"属性占位符中扩展属性?
更多我需要的解释:
@Value(${cfma.applicationUrl})).而且一定不能有任何Fallback,如果Tomcat中没有定义属性,应用程序一定不能启动!context:property-placeholder他们没有合并:@参见https://jira.springsource.org/browse/SPR-4881上的评论- 他们解释了这种行为.
当我谈论Tomcat参数时,我正在谈论这样的一些想法:
context.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Parameter name="cfmt.applicationBaseUrl"
value="http://localhost/demoApp" override="false"/>
</Context>
Run Code Online (Sandbox Code Playgroud) 我在春天遇到动态表单的问题.在我们的表单中,我们想要指定标题,并添加一些问题.我们有一个"添加"按钮,用于使用jquery添加问题输入表单.
我们的表格在要求时有一个问题栏.每次按下"添加"按钮时,都会添加额外的字段.提交时似乎没有提交额外的字段(第一个字段是由控制器接收的).为什么没有收到额外的字段?
我大致基于这个动态绑定列表示例的代码.
我的模型包括一个"报告"类,它有一个"标题"和一个"研究问题"列表.
下面是两个模型类的简短版本.Roo照顾所有的吸气者和制定者
@Entity
@RooJavaBean
@RooEntity
public class Report{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@NotEmpty
private String title;
@OneToMany(mappedBy="report")
private List<Researchquestion> researchquestions;
}
@Entity
@RooJavaBean
@RooEntity
public class Researchquestion {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@NotEmpty
private String question;
}
Run Code Online (Sandbox Code Playgroud)
这里是表单的jspx
<div xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:form="http://www.springframework.org/tags/form"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:spring="http://www.springframework.org/tags"
version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<spring:url value="/admin/report/appendquestion" var="insert_url"/>
<script type="text/javascript">
$(document).ready(function() {
var questionPosition = 0;
$("#addQuestionButton").click(function() {
questionPosition++; …Run Code Online (Sandbox Code Playgroud) 我有两种单元测试(不是集成测试).由于Spring Security的一些奇怪行为,我需要先运行所有正常测试,然后再运行安全测试.
我正在使用Junit(所以我不能使用任何TestNG组).
所以我所做的是指定两组包含并排除规则.
<excludes>
<exclude>**/*SecurityTest.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
Run Code Online (Sandbox Code Playgroud)
和
<excludes>
</excludes>
<includes>
<include>**/*SecurityTest.java</include>
</includes>
Run Code Online (Sandbox Code Playgroud)
如果我用手在我的pom中更换它们,那么我可以进行正常或安全测试.但是我当然希望在每个版本中运行这两种测试.
我的第一次尝试是有两个完整的maven-surefire-plugin配置.但是后来maven只考虑了他们中的最后一个.
我的下一个尝试是使用两个execution定义,但是然后surefire似乎完全忽略了规则并且混合了两种测试.
所以我的一般问题是如何为maven surefire指定两个文件集,以便它们将被逐个执行?更具体地说明如何指定两个不同的文件集.
执行配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<junitArtifactName>junit:junit</junitArtifactName>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea</argLine>
</configuration>
<executions>
<execution>
<id>normal-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/Abstract*.java</exclude>
<exclude>**/*_Roo_*</exclude>
<exclude>**/*SecurityTest.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>security-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/Abstract*.java</exclude>
<exclude>**/*_Roo_*</exclude>
</excludes>
<includes>
<include>**/*SecurityTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我想在springMVC3中使用异常处理程序捕获一个错误.我注释了异常.i可以捕获throwable和任何异常.但是当我尝试使用Error.It没有捕获异常.任何想法,为什么它如此.下面的代码捕获例外
ExceptionHandler(InvalidDataException.class)
public ModelMap handleException(InvalidDataException ex) {
logger.debug("exception catched :" + ex);
return new ModelMap();
}
Run Code Online (Sandbox Code Playgroud)
但下面没有抓住.
@ExceptionHandler(Error.class)
public ModelMap handleException(Error ex) {
logger.debug("exception catched :" + ex);
return new ModelMap();
}
Run Code Online (Sandbox Code Playgroud) 我应该使用<h:outputText value="static text"/>或直接写入static text到xhtml文件打印文本是静态的?
示例 - 带输出文本:
<h:outputText value="User Name:"/>
<h:outputText value="#{currentUser.name}"/>
Run Code Online (Sandbox Code Playgroud)
示例 - 直接:
User Name:
<h:outputText value="#{currentUser.name}"/>
Run Code Online (Sandbox Code Playgroud) private HibernateTemplate hibernateTemplate;
public void setSessionFactory(SessionFactory sessionFactory) {
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
Run Code Online (Sandbox Code Playgroud)
什么是SessionFactory类?我们为什么用它?什么是hibernateTemplate类用于?
<bean id="myUserDAO" class="com.mysticcoders.mysticpaste.services.ContactSerImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.mysticcoders.mysticpaste.model.Contact</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
这在bean中做了什么
我有一个应用程序,其前端基于Spring Roo 1.1.2 jspx文件.
每个思考在Tomcat 6中都可以正常工作,但如果我在Websphere 7中部署相同的应用程序(类加载器:父最后一个),那么我得到一个异常:
java.lang.ClassCastException:java.lang.NullPointerException与javax.el.ELException不兼容
[13.04.11 09:53:55:493 UTC] 00000026 servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet /WEB-INF/layouts/default.jspx in application cyber. Exception created : com.ibm.websphere.servlet.error.ServletErrorReport: java.lang.ClassCastException: java.lang.NullPointerException incompatible with javax.el.ELException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:693)
at com.ibm._jsp._default_5F_jspx._jspService(_default_5F_jspx.java:123)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1595)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:104)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:895)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:932)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:239)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:341)
at org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
...
Caused by: java.lang.ClassCastException: java.lang.NullPointerException incompatible …Run Code Online (Sandbox Code Playgroud) 我在Spring应用程序中使用Jackson 1.8.3将Java对象映射到JSON.
我的一个Java Class(Child)扩展了一个超类(Parent),它是Libary的一部分,所以我无法修改它.(特别是我无法添加注释.)
我正在使用,@JsonAutoDetect(JsonMethod.NONE)因为我只需要来自对象的一小部分字段,而不是我正在使用的@JsonProperty.
class Parent {
public long getId(){...};
...
}
@JsonAutoDetect(JsonMethod.NONE)
class Child extends Parent {
@JsonProperty
private String title;
}
Run Code Online (Sandbox Code Playgroud)
但我需要的一个领域是id来自超类的字段,但我不知道如何告诉杰克逊注意这个字段,而不修改父类(因为我无法修改它).
Eclipse标记此红色下划线的问题,如果将鼠标放在该行上方,则会弹出错误描述. - 如何看到文本光标的相同错误描述?
probelm/marker视图不是解决方案,因为它们将显示所有错误,我只需要"当前"错误.
解决方案必须没有鼠标!
我是Spring的新手.我下载了SpringToolSuite 3.7.2,我正在尝试创建一个简单的SpringBootApplication.我转到File-> New Spring Starter Project,选择Type as Maven项目和Under dependencies选择Web,然后单击Finish.我在pom.xml中的父标记上出错,也无法看到maven依赖库.我试图右键单击项目 - >选择Maven->更新项目 - >选中所有框并更新但不起作用.我还尝试清理C:{User} .m2下的存储库清理并重建项目,但对我不起作用.STS的屏幕截图
项目构建错误:com.example的不可解析的父POM:demo:0.0.1-SNAPSHOT:无法传输工件org.springframework.boot:spring-boot-starter-parent:pom:1.4.3.RELEASE from/to中心(https://repo.maven.apache.org/maven2):repo.maven.apache.org和'parent.relativePath'指向无本地POM
请告诉我我错过了什么.下面是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringApplication1</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud) java ×6
spring ×6
eclipse ×1
hibernate ×1
jackson ×1
jquery ×1
jsf-2 ×1
json ×1
jspx ×1
maven ×1
properties ×1
spring-boot ×1
spring-roo ×1
testing ×1
unit-testing ×1
websphere-7 ×1