머핀
84
2019-01-13 10:32:52 작성 2019-01-13 14:30:06 수정됨
4
101

스프링에서 gmail로 파일을 첨부해서 보내는것 오류(찾았습니다. 감사합니닷!) BindingResult를 빼니까 되네요



Type Exception Report

Message Request processing failed; nested exception is java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be immediately after the model attribute argument in the controller method signature: public java.lang.String com.map.board.HomeController.mailSending(org.springframework.ui.Model,org.springframework.validation.BindingResult,org.springframework.web.multipart.MultipartHttpServletRequest)

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be immediately after the model attribute argument in the controller method signature: public java.lang.String com.map.board.HomeController.mailSending(org.springframework.ui.Model,org.springframework.validation.BindingResult,org.springframework.web.multipart.MultipartHttpServletRequest)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

Root Cause

java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be immediately after the model attribute argument in the controller method signature: public java.lang.String com.map.board.HomeController.mailSending(org.springframework.ui.Model,org.springframework.validation.BindingResult,org.springframework.web.multipart.MultipartHttpServletRequest)
	org.springframework.web.method.annotation.ErrorsMethodArgumentResolver.resolveArgument(ErrorsMethodArgumentResolver.java:62)
	org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
	org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

Note The full stack trace of the root cause is available in the server logs.


0
0
  • 답변 4

  • lazer
    1k
    2019-01-13 13:32:14

    controller 에 들어온 request 를 검증하다 오류난 것 같습니다만

    1
  • 머핀
    84
    2019-01-13 13:55:07

    package com.map.board;

    import java.io.File;

    import java.io.FileNotFoundException;

    import java.io.FileOutputStream;

    import java.io.InputStream;

    import java.io.OutputStream;

    import java.util.List;


    import javax.annotation.Resource;

    import javax.mail.internet.MimeMessage;

    import javax.mail.internet.MimeUtility;



    import org.springframework.beans.factory.annotation.Autowired;

    import org.springframework.core.io.FileSystemResource;

    import org.springframework.mail.javamail.JavaMailSender;

    import org.springframework.mail.javamail.MimeMessageHelper;

    import org.springframework.stereotype.Controller;

    import org.springframework.ui.Model;

    import org.springframework.validation.BindingResult;

    import org.springframework.web.bind.annotation.RequestMapping;

    import org.springframework.web.bind.annotation.RequestMethod;

    import org.springframework.web.bind.annotation.ResponseBody;

    import org.springframework.web.multipart.MultipartFile;

    import org.springframework.web.multipart.MultipartHttpServletRequest;

    import org.springframework.web.util.WebUtils;


    import com.map.join.joinVO;

    import com.map.joinBiz.joinBiz;


    @Controller

    public class HomeController {

    //값주입

    @Autowired

    private JavaMailSender mailSender;


    @RequestMapping(value = "map.do")

    public String map() {

    return "map";

    }

     

      // mailForm

      @RequestMapping(value = "mailForm.do")

      public String mailForm() {

       

        return "mailForm";

      }  

     

      // mailSending 코드

      @RequestMapping(value = "mailSending.do", method=RequestMethod.POST)

      @ResponseBody

      public String mailSending(Model model, BindingResult result, MultipartHttpServletRequest multi) {

      InputStream inputStream = null;

      OutputStream outputStream = null;


    //파일경로

      String path = "";

    try {

    path = WebUtils.getRealPath(multi.getSession().getServletContext(), "/storage");

    } catch (FileNotFoundException e1) {

    e1.printStackTrace();

    }

           System.out.println(path);

          //파일들을 List형식으로 보관

          List<MultipartFile> files = multi.getFiles("files");

           

          File file = new File(path);

         //파일이 없다면 디렉토리를 생성

         if (file.exists() == false) {

             file.mkdirs();

         }

       //메일보내기기능

        String setfrom = "yunjae830@gmail.com";         

        String tomail  = multi.getParameter("tomail");     // 받는 사람 이메일

        String title   = multi.getParameter("title");      // 제목

        String content = multi.getParameter("content");    // 내용

        File filename = null;

        try {

        MimeMessage message = mailSender.createMimeMessage();

          MimeMessageHelper messageHelper 

                            = new MimeMessageHelper(message, true, "UTF-8");

          

         for (int i = 0; i < files.size(); i++) {

        inputStream = files.get(i).getInputStream();

            System.out.println(files.get(i).getOriginalFilename() +" 업로드");

            filename = new File(path+ "/" +files.get(i).getOriginalFilename());

            if(!filename.exists()) {

            filename.createNewFile();

    }

            outputStream = new FileOutputStream(filename);

            int read = 0;

    byte[] b = new byte[(int)files.get(i).getSize()];

    while((read=inputStream.read(b)) != -1) {

    outputStream.write(b, 0, read);

    }

            //파일첨부

            FileSystemResource fsr = new FileSystemResource(filename);

            messageHelper.addAttachment(MimeUtility.encodeText(files.get(i).getOriginalFilename(), "UTF-8", "B"), fsr);

         }     

     

          messageHelper.setFrom(setfrom);  // 보내는사람 생략하거나 하면 정상작동을 안함

          messageHelper.setTo(tomail);     // 받는사람 이메일

          messageHelper.setSubject(title); // 메일제목은 생략이 가능하다

          messageHelper.setText(content);  // 메일 내용-

         

          mailSender.send(message);

        }catch(Exception e) {

        e.printStackTrace();

        }

        return "";

      }

    //--------------------   회원가입

      @Autowired

      private joinBiz biz;

      

      @RequestMapping(value="joinform.do")

      public String joinform() {

      

      return "joinform";

      }

      

      @RequestMapping(value="join.do")

      public String join(Model model, joinVO dto) {

      int res = biz.joinInsert(dto);

      if(res==0) {

      return "joinform";

      }else if(res==1) {

      return "suc";

      }

      return "";

      }

      

    }


    0
  • 머핀
    84
    2019-01-13 13:55:58 작성 2019-01-13 14:12:05 수정됨
    파일을 업로드해서 가져오고 그것을 gmail에  mailSender로 보내는 과정인데 처음에는 잘돌아갔던 코드인데 회원가입패키지 만들고 pom.xml추가하고 root-context에 dataSource와 sqlSession, sqlSessionTemplate을 추가하면서 이런 오류가 나오는거 같은데 문제가 뭔지..모르겠어요
    0
  • lazer
    1k
    2019-01-13 15:28:52

    BindingResult 를 인자에서 빼고 실행해보세요.


    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.