简体   繁体   中英

Hotswap Agent, add New Classes

can I add new class on Hotswap Agent? I try changing name methods, body of methods, fields, and works fine, but when I add new class and call it on another the app crash, don do the content of that class and not show errors.

package test;

public class TestNewClass 
{
        public void test()
    {
        System.out.println("test new class");
    }
}



@Controller
public class MenuController extends MainController
{
    @RequestMapping(value = "/menu/getMenu", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE_UTF_8)
        @ResponseBody
        public String getMenu(HttpServletResponse httpRessponse)
        {
            System.out.println("test 3 "+test);
            UserVitrina user = getUserVitrina();
            MenuHandler menuHandler = new MenuHandler();
            try
            {
                genericBO.openSessionTransaction();
                Map menu = menuHandler.getMenu(user.getIdUsuario());
                genericBO.commitTransaction();
                return new Gson().toJson(menu);
            }
            catch (Exception ex)
            {
                new Log().printLogError("MENU. Error obtener menu.", ex, (user == null ? "usuario nulo" : user.getUsername()), null, Resources.LogName.DEBUG);
                httpRessponse.setStatus(HttpStatus.BAD_GATEWAY.value());
                genericBO.abortTransaction();
                return new Gson().toJson(new MessageServer().generateMessageError(ex));
            }
            finally
            {
                genericBO.closeSession();
            }
        }
}

If you do hotswap with your IDE, it swaps only existing classes. New classes are loaded by standard mechanism from the classpath. Is your new class on the classpath? If you have eg multimodule maven project, you may be able to swap classes from dependent module, but new classes are loaded only from built jar files.

To solve this add extraClaspath ( http://hotswapagent.org/mydoc_configuration.html ) to your hotswap-agent.properties file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM