Skip to content

Instantly share code, notes, and snippets.

View edermfl's full-sized avatar

Eder Leite edermfl

View GitHub Profile
public class Objeto4{
public void metodoD(){
// ano e mes são recuperados do Contexto, cujo está guardado na Thread local
final Integer ano = GerenciadorContexto.getParametros().getAno();
final Integer mes= GerenciadorContexto.getParametros().getMes();
}
public void metodoE(){
// cnpj são recuperados do Contexto, cujo está guardado na Thread local
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.username=<seu_email>@gmail.com
spring.mail.password=<chave de 16 digitos gerada pelo Google Account>
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.quitwait=false
spring:
# ... outras configurações
mail:
host: smtp.gmail.com
port: 587
protocol: smtp
username: <seu_email>@gmail.com
password: <chave de 16 digitos gerada pelo Google Account>
properties:
mail:
@edermfl
edermfl / spring_boot_enviando_email_SenderMailService.java
Last active February 8, 2017 10:56
Serviço responsável pelo envio do e-mail
@Component
public class SenderMailService {
@Autowired
private JavaMailSender mailSender;
private void enviar() {
SimpleMailMessage email = new SimpleMailMessage();
email.setTo("teste@gmail.com");
email.setSubject("Teste envio de e-mail");
@RunWith(SpringRunner.class)
@SpringBootTest
public class SenderMailServiceTest {
@Autowired
SenderMailService senderMailService;
@Test
public void testEnvioEmail() {
senderMailService.enviar();
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
// ...
compile('org.springframework.boot:spring-boot-starter-mail')
// ...
public class ProxyMapHandler implements MethodHandler {
private Map<String, Object> mapaRegistro;
public ProxyMapHandler(final Map<String, Object> pMapaRegistro) {
mapaRegistro = pMapaRegistro;
}
public Object invoke(final Object self, final Method thisMethod, final Method proceed, final Object[] args) throws Throwable {
// -> getAlgumaPropriedade - algumaPropriedade
public static <T> T criarProxyBaseadoNoMapa(final Class<T> pTipoDoProxy, final Map<String, Object> pMapaRegistro) {
final ProxyFactory factory = new ProxyFactory();
if (pTipoDoProxy.isInterface()) {
factory.setInterfaces(new Class[] { pTipoDoProxy });
} else {
factory.setSuperclass(pTipoDoProxy);
}
Object newProxyInstance = null;
try {
newProxyInstance = factory.create(new Class<?>[0], new Object[0], new ProxyMapHandler(pMapaRegistro));
public Object invoke(final Object self, final Method thisMethod, final Method proceed, final Object[] args) throws Throwable {
Object retorno = null;
final String methodName = thisMethod.getName();
if (self instanceof FacesContext) {
if ("addMessage".equals(methodName)) {
final FacesMessage facesMessage = (FacesMessage) args[1];
listaMensagensJsf.add(facesMessage);
} else if ("getMessages".equals(methodName)) {
retorno = listaMensagensJsf.iterator();
} else if ("getExternalContext".equals(methodName)) {