Skip to content

Instantly share code, notes, and snippets.

View Qkyrie's full-sized avatar

QDS Qkyrie

  • Layer 0
View GitHub Profile
@Qkyrie
Qkyrie / thymeleaf-data-attributes.xhtml
Created December 13, 2013 10:05
Thymeleaf Data attributes
(form 2.1+)
<div data-th-attr="data-percent=${level90s}"></div>
-- OR --
<div th:attr="data-percent=${level90s}"></div>
@Qkyrie
Qkyrie / AppConfig.java
Created December 5, 2013 10:39
PropertyPlaceholder in spring
@Configuration
@ImportResource("classpath:/com/acme/properties-config.xml")
public class AppConfig {
private @Value("${jdbc.url}") String url;
private @Value("${jdbc.username}") String username;
private @Value("${jdbc.password}") String password;
public @Bean DataSource dataSource() {
return new DriverManagerDataSource(url, username, password);
}
@Qkyrie
Qkyrie / Bean.java
Created December 5, 2013 10:32
@bean with destroy and init methods
public class Foo {
public void init() {
// initialization logic
}
}
public class Bar {
public void cleanup() {
// destruction logic
}
}
@Qkyrie
Qkyrie / AppConfig.java
Created December 5, 2013 10:27
A simple JavaConfig @configuration class. The equivalent xml is also added
@Configuration
public class AppConfig {
@Bean
public MyService myService() {
return new MyServiceImpl();
}
}
@Qkyrie
Qkyrie / Config.java
Created December 5, 2013 10:12
Spring Component Scanning Tip The use of <context:component-scan> implicitly enables the functionality of <context:annotation-config>. There is usually no need to include the <context:annotation-config> element when using <context:component-scan>.
Configuration
@ComponentScan("com.company") // search the com.company package for @Component classes
@ImportXml("classpath:com/company/data-access-config.xml") // XML with DataSource bean
public class Config {
}
@Qkyrie
Qkyrie / CustomQualifier.java
Created December 5, 2013 10:05
A Custom Qualifier for Spring
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface Offline {
}
@Qkyrie
Qkyrie / AbstractMockedTest.java
Created December 5, 2013 09:27
AbstractMockedTest. A Basic class where we init the mocks
public class AbstractMockedTest {
@Before
public void initMockitoAnnotations() {
MockitoAnnotations.initMocks(this);
}
protected void assertEmpty(Collection collection) {
Assert.assertTrue("Collection was expected to be empty", collection.isEmpty());
}
@Qkyrie
Qkyrie / GoogleAnalyticshandler.java
Created December 3, 2013 13:47
GoogleAnalytics as a jsp-tag
package be.ipc.storm.common.tags;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.util.Properties;
/**
* Created by Davy van Roy.
@Qkyrie
Qkyrie / Logout.jsp
Created December 3, 2013 12:58
Redirect in jsp page to logout
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta HTTP-EQUIV="REFRESH" content="0; url=${pageContext.request.contextPath}/j_spring_security_logout">
<title></title>
</head>
<body>
</body>
@Qkyrie
Qkyrie / web.xml
Created November 30, 2013 01:48
Default 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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- Map all errors to Spring MVC handler method. See CustomErrorController.generalError() -->
web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>