Tag: spring mvc

绘图图在Web应用程序中

我正在使用Spring开发一个Web应用程序。 我需要绘制图表并将其显示给用户。 值存储在数据库中。 我该如何实现这一目标?

将文件从SFTP直接下载到HTTP响应,而不使用中间文件

我正在尝试使用Java JSsch库通过SFTP下载文件。 我成功地将文件下载到本地目录。 **但是,我只需要将文件直接下载到浏览器而不提供任何本地目标路径(例如如何在Chrome中下载文件)。 我使用Spring控制器AngularJS Promise来捕获响应。 以下是我的代码。 @RequestMapping(value = “/downloadAttachment”, method = RequestMethod.POST, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public void downloadAttachment( @RequestParam(value = “fileName”) String fileName, @RequestParam(value = “filePath”) String filePath, @RequestParam(value = “fileId”) String fileId, HttpServletResponse response, Locale locale) throws Exception { InputStream is = null; if(!fileName.isEmpty() && !filePath.isEmpty() && !fileId.isEmpty()){ String directory = filePath; java.util.Properties […]

Spring Oauth2:在SecurityContext中找不到身份validation对象

我有一个项目,我实现了Spring安全性和Spring OAuth2 Security。当我请求访问令牌时,它运行良好但是当我使用访问令牌请求资源时,我得到了“在SecurityContext中找不到身份validation对象”。 我的项目的SecurityContext是: <!– –> <!– –> <!– –> <!– –> <!– –> <!– –> <!– –> 我使用http:// localhost:8060 / oauth / token请求令牌?grant_type =密码&client_id = nokia3320&client_secret = 0987654321&username = subash&password = 123456我得到了以下回复 { “access_token”: “9f5a89ce-a0d9-4d65-8e83-5d3b16d8c025”, “token_type”: “bearer”, “refresh_token”: “c2ac82ec-9f41-46dd-b7c2-4772c018505c”, “expires_in”: 499, “scope”: “read trust write” } 当我尝试使用http:// localhost:8060 / Api / currencyList在authorizatioin错误中使用访问令牌访问资源时,我得到了以下响应 { “error”: […]

如何在spring mvc中使用ehcache和hibernate

我是spring-mvc的新手,希望在hibernate中集成ehcache作为二级缓存。 我按照本教程ehcache现在我的hibernate.xml中的条目如下: true ehcache.xml true ehcache.xml中的条目如下: 我们遵循mvc模型,在模型中我定义了annootation @Entity @Cache(usage=CacheConcurrencyStrategy.READ_ONLY, region=”department”) 现在问题是如何在服务层中开始使用此缓存。 我没有在我的项目中创建hibernateUtil.java。 我们正在使用基于web的spring-hibernate mvc应用程序。 现在如何开始,我没有得到。

密码编码 – BCrypt – 不授权哈希密码,仅授权纯文本

我有一个宠物项目,我一直在慢慢削减,最近我决定为用户加入BCrypt密码编码。 我遇到的问题是它现在从未授权任何用户我已经拥有它,我无法弄清楚原因。 希望你们能帮忙。 以下是我的SecurityConfig.java文件中的配置 @Autowired private PasswordEncoder passwordEncoder; @Override protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder); } @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } 我的控制器注册新用户并将其记录在: @RequestMapping(value = “/user_create”, method = RequestMethod.POST) public String createUser(@ModelAttribute User user) { user.setPlain(user.getPassword()); user.setPassword(BCrypt.hashpw(user.getPassword(),BCrypt.gensalt())); userInterface.saveUser(user); return “redirect:/”; } 创建新用户可以完美地工作(将其加载到DB中),结果如下所示: ID | USERNAME | PLAIN_PASSWORD | HASHED_PASSWORD 1 […]

如何解决 – 创建名为’defaultController’的bean时出错

我是Spring MVC和Hibernate的新手。 几天我试图做一个简单的春季项目,但在那里遇到了一些错误。 错误说org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为’CustomerDAOImp’的bean时出错 这是我的错误 HTTP状态500 – 内部服务器错误 类型exception报告 messageInternal服务器错误 description服务器遇到内部错误,导致无法完成此请求。 例外 javax.servlet.ServletException:servlet调度程序的Servlet.init()引发了exception根本原因 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为’CustomerDAOImp’的bean时出错:通过字段’sessionFactory’表示的不满意的依赖关系; 嵌套exception是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型’org.hibernate.SessionFactory’的限定bean可用:预期至少有1个bean可以作为autowire候选者。 依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}根本原因 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型’org.hibernate.SessionFactory’的限定bean可用:预计至少有一个bean可以作为autowire候选者。 依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}注意GlassFish Server Open Source Edition 4。1。1日志中提供了exception的完整堆栈跟踪及其根本原因。 GlassFish Server开源版4.1.1 我用maven multi模块完成了这个项目。 这里’CustomerDAOImp’是我在CustomerDAOImp类中定义的存储库的名称。 这是扩展GenericImp类并实现CustomerDAO接口的java类,并且进一步的CustomerDAO扩展了GenericDAO接口。 CustomerDAOImp @Repository(value = “CustomerDAOImp”) public class CustomerDAOImp extends GenericDAOImp implements CustomerDAO{ } CustomerDAO public interface CustomerDAO extends GenericDAO{ } GenericDAO […]

Spring安全性 – 方法级安全性不适用于从另一个方法调用

假设我有两种方法 @Secured(“ROLE_ADMIN”) @RequestMapping(value = “/methodA”, method = RequestMethod.GET) public void MethodA(){ // code } 和另一种调用第一种方法的方法 @RequestMapping(value = “/MethodB”, method = RequestMethod.GET) public void MethodB(){ MethodA(); //code } 如果我使用权限ROLE_USER登录到应用程序并尝试访问URL /methodA ROLE_USER ,我将获得访问被拒绝的exception – 完美! 但是,如果我访问URL /methodB即使我使用ROLE_USER权限访问MethodA,我也不会获得访问被拒绝的exception。 是应该像那样工作还是我做错了什么? PS:这不是一个实时应用场景,但我只是在玩代码。

启用JSP Custom taglib以使用spring服务bean

我正在使用Spring MVC 3.2.4(Spring Core 3.2.4)开发一个Web应用程序,后端使用jpa和hibernate。 目前正在使用Tomcat v6.0进行测试。 我有一个案例,当我创建一个JSP自定义标记库lib(使用jsp-api 2.1.1和servlet-api 2.5),这是一个自定义查找下拉列表,我会给它查找类型,它将从将此类型下的项目DB作为列表中的项目进行渲染。 自定义taglib类基本上看起来像这样: public class LookupsTag extends SimpleTagSupport { @Autowired private static LookupService lookupService; private String type; public void doTag() throws JspException, IOException { List items = lookupService.findByType(getType()); StringBuffer buff = new StringBuffer(); buff.append(“”); //…adding items… buff.append(“”); getJspContext().getOut().write(buff.toString()); } //getters and setters } 我已经相应地创建了tld文件。 一旦我尝试使用此自定义标记查看页面,就会抛出NullPointerException ,因为在doTag()方法中, lookupService实例为null […]

将照片上传到OpenShift。 Spring MVC

我在OpenShift服务器上部署了我的Spring MVC应用程序的.war文件。 每个用户都可以更改照片。 它适用于我的localhost,但我需要在OpenShift服务器上传照片并将每张照片的路径放到数据库中。 这是我上传文件的方法 @RequestMapping(value = “/user/updateinfo”, method = RequestMethod.POST) public String postAvatar(@RequestParam(“file”) MultipartFile file, Principal principal) { if (file.isEmpty()) { return “redirect:/user”; } if (!file.isEmpty()) { try { String relativeWebPath = “/resources/avatars/”; String absoluteFilePath = context.getRealPath(relativeWebPath); String name = file.getOriginalFilename(); // String name=file.getOriginalFilename(); System.out.println(absoluteFilePath); String path = absoluteFilePath + “/” + name; File […]

仅使用XML配置的Spring RESTful Web服务

我一直只使用XML配置来制作MVC Web应用程序。(没有注释) 现在我想用Spring创建一个RESTful Web服务,但我找不到任何不使用注释的教程。 有没有办法构建只有XML配置的RESTful Web服务? 或者我必须使用注释吗? 例如,您可以仅使用如下所示的XML配置部署MVC模式Web应用程序。 <!– –> 但是,当我尝试为URL映射方法时,我遇到了问题,例如HTTP方法:POST,URL:/ student / 1 / Adam – 这样我就可以添加学生了。 URL格式是这样的。 / [资源] / [ID] / [名] 我可以通过在条目键中放置一个模式来将/ student / 1 / Adam映射到控制器,但是我应该如何解析控制器中的URI? 我可以通过使用String.split()或类似的东西来解析URI,但我想知道是否已经有一些解决方案,以便我可以避免重新发明轮子。