我正试图用Spring MVC 3.0弄清楚,虽然我可以让它工作,但我似乎无法有效地处理这种特殊情况.
我有一个控制器,处理"/ {studyName} /模块"前缀,它看起来像这样: -
@Controller
@RequestMapping(value = "/{studyName}/module")
public class ModuleController {
@RequestMapping(...)
public ModelAndView getA(@PathVariable String studyName, ...) {
if (!validStudy(studyName)) { return bad request; }
...
}
@RequestMapping(...)
public ModelAndView getB(@PathVariable String studyName, ...) {
if (!validStudy(studyName)) { return bad request; }
...
}
@RequestMapping(...)
public ModelAndView getC(@PathVariable String studyName, ...) {
if (!validStudy(studyName)) { return bad request; }
...
}
@RequestMapping(...)
public ModelAndView getD(@PathVariable String studyName, ...) {
if (!validStudy(studyName)) { return bad request; …Run Code Online (Sandbox Code Playgroud) 在过去,我通过"添加后构建操作 - > SonarQube"在Jenkins中配置了Sonar.
现在,当我这样做时,我收到了这个警告:
不再建议使用SonarQube maven builder.最好在构建环境中设置SonarQube并使用标准的Jenkins maven目标.
要解决这个问题,我使用这个Maven插件
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.0.1</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在詹金斯的工作中,我执行了以下目标
-U clean test site sonar:sonar -Dsonar.host.url=http://my-sonar-server
Run Code Online (Sandbox Code Playgroud)
除了作业页面中的侧栏中缺少SonarQube链接外,一切都完美无瑕.
当我查看日志时,我看到了SonarQube链接: -
[INFO] Analysis report generated in 162ms, dir size=52 KB
[INFO] Analysis reports compressed in 47ms, zip size=27 KB
[INFO] Analysis report uploaded in 81ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://my-sonar-server/dashboard/index/org.project.test:test-webapp-war
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about …Run Code Online (Sandbox Code Playgroud) 请原谅我在这里提出这样一个简单的问题,因为我是Spring MVC 3.0的新手.我一直在阅读spring source website的文档几次.这是我在下面的问题中引用的代码片段: -
@RequestMapping("/pets/{petId}")
public void findPet(@PathVariable String petId, Model model) {
// implementation omitted
}
Run Code Online (Sandbox Code Playgroud)
如果我打算使用基于这个例子的URI模板,那么将@PathVariable类型设置为String总是比较好,即使我期望它是其他类型,例如int?文档说@PathVariable注释可以是任何简单类型,但如果Spring无法将无效petId转换为int(例如,用户输入一些字符而不是数字),它将抛出一个TypeMismatchException.
那么,验证器什么时候开始发挥作用?我是否将所有@PathVariable类型保留为String并使用验证器对String值执行验证,如果没有验证错误,则将String显式转换为所需类型?
谢谢.
我正在从Castor切换到JAXB2,以在XML和Java对象之间执行编组/解组.我在尝试配置多态对象集合时遇到问题.
示例XML
<project name="test project">
<orange name="fruit orange" orangeKey="100" />
<apple name="fruit apple" appleKey="200" />
<orange name="fruit orange again" orangeKey="500" />
</project>
Run Code Online (Sandbox Code Playgroud)
项目类
该oranges表工作正常,我看到列表中的2个橘子.但是,我不确定如何配置fruitList.本fruitList应该有3个水果:2个橘子和一个苹果.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Project {
@XmlAttribute
private String name;
@XmlElement(name = "orange")
private List<Orange> oranges = new ArrayList<Orange>();
// Not sure how to configure this... help!
private List<Fruit> fruitList = new ArrayList<Fruit>();
}
Run Code Online (Sandbox Code Playgroud)
水果类
水果是一个抽象的类.出于某种原因,将此类定义为抽象似乎会导致很多问题.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class Fruit {
@XmlAttribute
private String name;
}
Run Code Online (Sandbox Code Playgroud)
橙类
public …Run Code Online (Sandbox Code Playgroud) 我在尝试将Hibernate事务中的更改推送到数据库以使DbUnit在我的测试用例中正常工作时遇到问题.似乎DbUnit没有看到Hibernate所做的更改,因为它们还没有在事务结束时提交......而且我不确定如何重构我的测试用例以使其工作.
这是我过度简化的测试用例来证明我的问题: -
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:applicationContext-test.xml"
})
@TransactionConfiguration(transactionManager = "transactionManager")
@Transactional
public class SomeTest {
@Autowired
protected DataSource dataSource;
@Autowired
private SessionFactory sessionFactory;
@Test
public void testThis() throws Exception {
Session session = sessionFactory.getCurrentSession();
assertEquals("initial overlayType count", 4, session.createQuery("from OverlayType").list().size());
//-----------
// Imagine this block is an API call, ex: someService.save("AAA");
// But for the sake of simplicity, I do it this way
OverlayType overlayType = new OverlayType();
overlayType.setName("AAA");
session.save(overlayType);
//-----------
// flush has no effect here
session.flush(); …Run Code Online (Sandbox Code Playgroud) 由于GMaven已经停产,我一直在我的Maven项目中使用Groovy-Eclipse Compiler插件.我使用的版本是2.8.0-01,我特别使用了Groovy 2.1.我知道2.9.0-01-SNAPSHOT已经出去的时间最长,但是当它正式发布时没有ETA.
我的问题是......我可以安全地使用版本2.8.0-01与Groovy 2.3.5没有潜在的副作用吗?
谢谢.
我很难决定使用哪个"Open Session In View":使用Spring MVC的拦截器配置OpenSessionInViewInterceptor或在web.xml的过滤器中配置OpenSessionInViewFilter?根据我的研究,它们几乎完全相同,但我试图理解每种类型的差异和用法.
两者之间最大的区别在于那些不能在web.xml中使用过滤器的人(比如servlet 2.2及更早版本),他们唯一的选择就是使用OpenSessionInViewInterceptor.不知何故,我倾向于拦截器只是因为我必须为我的项目创建一个自定义拦截器,所以我想在Spring MVC配置文件中对所有这些"过滤器"进行分组,而不是在web.xml和我的自定义中使用OpenSessionInViewFilter Spring MVC配置文件中的拦截器.决定使用哪一个真的是一种蹩脚的方式,我的好奇心在这里杀了我.
有人可以分享你对此的看法吗?你们用哪一个?
谢谢.
在我的自定义身份验证提供程序中,我能够通过我的Service API获取域对象,但是当我从一个域对象爬到另一个域对象以获得某些值来执行其他检查时,Spring抱怨Hibernate会话不存在: -
domain.getAnotherDomain().getProperty(); // epic FAIL
Run Code Online (Sandbox Code Playgroud)
我有以下AOP事务用事务包装我的所有项目API,我很确定我的自定义身份验证提供程序属于以下模式: -
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:advisor pointcut="execution(* my.project..*.*(..))" advice-ref="txAdvice" />
</aop:config>
Run Code Online (Sandbox Code Playgroud)
我也配置了OpenSessionInView过滤器,但我认为无论如何都不适用于Spring Security.
我想我可以创建一个特定的服务API来执行所有必需的检查,但我很好奇为什么我无法使用正确的事务包装我的自定义身份验证提供程序.
任何解释?谢谢.
目前,我有这样的事情: -
public class MyHolder<T> {
private T value;
public MyHolder(T t) {
this.value = t;
}
public T getValue() {
return first;
}
public void setValue(T t) {
this.first = t;
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个,我可以像这样使用它: -
MyBean bean = new MyBean();
MyHolder<MyBean> obj = new MyHolder<MyBean>(bean);
obj.getValue(); // returns bean
Run Code Online (Sandbox Code Playgroud)
而不是调用的getter/setter是中getValue()和setValue(..),是有可能"泛型化"是吗?
从本质上讲,拥有它会很好,getMyBean()并且setMyBean(..)取决于传入的类型.虽然这是一个非常简单的例子,但是如果我创建一个带有N个泛型属性的泛型持有者类,那么将它称为有意义的东西会很好代替getValue1()或getValue2()等等.
谢谢.
我在试图让checkstyle在Hudson/Jenkins中正常工作时遇到了问题.
我创建了一个自定义的checkstyle规则,其中包含非常少的规则(只是为了查看它是否有效)并将其放在某个服务器中: -
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="RegexpSingleline">
<property name="format" value="\s+$" />
<property name="minimum" value="0" />
<property name="maximum" value="0" />
<property name="message" value="Line has trailing spaces." />
</module>
</module>
Run Code Online (Sandbox Code Playgroud)
我有一个看起来像这样的父pom: -
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a.b</groupId>
<artifactId>c</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.4</version>
<configuration>
<configLocation>http://server/checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
</project> …Run Code Online (Sandbox Code Playgroud) java ×10
hibernate ×3
spring ×3
spring-mvc ×3
jenkins ×2
maven ×2
checkstyle ×1
dbunit ×1
generics ×1
groovy ×1
hudson ×1
interceptor ×1
jaxb ×1
jaxb2 ×1
junit ×1
maven-2 ×1
maven-3 ×1
sonarqube ×1
sonarqube5.1 ×1
validation ×1