以编程方式使用动态用户名和密码配置Hibernate

我正在实现一个Web应用程序,用户需要使用他的数据库用户名和密码进行身份validation。 我想使用相同的输入用户名和密码来连接数据库。 换句话说,我想在hibernate配置文件中这两个字段:(dbusername和dbpassword): dbusername dbpassword 可以根据输入用户名和密码的用户登录Web应用程序进行dynimacally填充。 这可以吗? 谢谢

在Java中对Months和Year进行排序的最佳方法

我有一个列表,其中包含格式(MON-YYYY)字符串格式的日期,我需要对此列表进行排序。我一直遵循的方法是读取列表并使用日期格式转换字符串并使用比较选项,但我我没有得到理想的结果 代码片段 List abc = new ArrayList(); List xyz = new ArrayList(); abc.add(“JAN-2010”); abc.add(“JAN-2011”); abc.add(“APR-2013”); abc.add(“NOV-2009”); try { for (String abc1 : abc) { Date date; date = new SimpleDateFormat(“MMM-yyyy”, Locale.ENGLISH) .parse(abc1); xyz.add(date); } Collections.sort(xyz, new Comparator() { public int compare(Date arg0, Date arg1) { // return arg0.getDate().compareTo(o2.getDate()); return arg0.compareTo(arg1); } }); for (Date date1 […]

在Spring Data JPA存储库中使用@Primary

如果有人需要在Spring Data存储库上使用@Primary:看起来Spring Data JPA会忽略存储库上的@Primary注释。 作为一种解决方法,我创建了BeanFactoryPostProcessor ,它检查给定的存储库是否有@Primary注释并将该bean设置为主要。 这是代码: @Component public class SpringDataPrimaryPostProcessor implements BeanFactoryPostProcessor { public static final String REPOSITORY_INTERFACE_PROPERTY = “repositoryInterface”; @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { makeRepositoriesPrimary(getRepositoryBeans(beanFactory)); } protected List getRepositoryBeans(ConfigurableListableBeanFactory beanFactory) { List springDataRepositoryDefinitions = Lists.newArrayList(); for (String beanName : beanFactory.getBeanDefinitionNames()) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDefinition.getBeanClassName(); try […]

将HTTP 407错误作为IOException

我在我的Android应用程序中使用HttpURLConnection通过需要身份validation的代理。 这是我的代码,我会在遇到问题后解释你。 HttpURLConnection connection = null; int responseCode = -1; try { connection = (HttpURLConnection) myUrl.openConnection(); connection.setInstanceFollowRedirects(false); connection.setConnectTimeout(DEFAULT_TIMEOUT); connection.setReadTimeout(DEFAULT_TIMEOUT); responseCode = connection.getResponseCode(); System.out.println(“ResponseCode = ” + responseCode); } catch (IOException e) { System.out.println(“Exception : ” + e.getMessage()); } 我的问题是我在getResponseCode()方法上得到一个例外,它有以下消息: Failed to authenticate with proxy 。 通常,这个特定的错误有一个http错误代码:407。但是在这里我只得到了一个exception,但没有带有407值的响应代码。 我有解决方案应用登录名和密码连接到代理,但我想只在出现407错误的情况下应用此解决方案(而不是每次我捕获exception)。 任何想法将不胜感激。 谢谢。

具有JPA的不同数据库的不同列类型

根据使用的数据库,是否可以使用JPA定义不同的列类型? 我需要将id存储为uuid,它必须是可以保持的。 那就是问题所在。 PostgreSQL有’uuid’,MSSQL’uniqueidentifier’而且Oracle什么都没有,我想必须使用’RAW’。 有人有想法可以帮助我吗? 编辑:当前使用java.util.UUID生成ID并将其作为varchar存储在数据库中。 但是由于该数据类型的性能问题,我想将id存储为uuid类型。 对于Oracle,必须使用RAW类型,因为不存在uuid类型。 如何告诉JPA在Oracle中使用带PostgreSQ / MSSQL和RAW类型的uuid类型?

Spring MongoDB和Apache Shiro

我试图使用Apache Shiro与Spring和MongoDB。 我正在使用自动assembly的Spring Data Repositories。 我为Shiro创建了自己的自定义域,它使用Spring Data存储库与Mongo交谈: public class PlatformRealm extends AuthorizingRealm { @Autowired(required = true) protected UserRepository userRepository = null; @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { … } } 我看到的问题是userRepository没有自动assembly。 我在控制台输出中得到以下行,引用PlatformRealm: INFO org.springframework.web.context.support.XmlWebApplicationContext – Bean ‘platformRealm’ of type [class com.resonance.platform.core.security.PlatformRealm] is not eligible for getting processed by all BeanPostProcessors (for example: not […]

JMX端口动态分配

我有16个Java进程,在一台机器上运行相同的主方法和参数。 我希望通过JConsole远程监控这些。 像-Dcom.sun.management.jmxremote.port=5000这样的硬编码端口号将无法工作,因为这些进程使用相同的配置,并且无法使用相同的端口。 JVM是否可以为16个进程中的每个进程动态选择不同的端口?

Spring java.lang.IllegalStateException:在提交响应后无法创建会话

我在我的spring应用程序中遇到会话管理问题,这是方案。 当用户打开我的应用程序URL时,它会要求提供凭据并登录。用户进入后,如果他打开一个新选项卡并粘贴我的应用程序URL,它将再次请求凭据并且用户登录。 现在,如果用户在tab1中注销,并且如果用户想要在第二个选项卡中执行任何操作,则用户会在下面的堆栈跟踪中收到错误并注销。 Oct 10, 2014 3:11:27 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [CollPortal] in context with path [/CollPortal] threw exception java.lang.IllegalStateException: Cannot create a session after the response has been committed at org.apache.catalina.connector.Request.doGetSession(Request.java:2886) at org.apache.catalina.connector.Request.getSession(Request.java:2316) at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:898) at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:910) at com.dc.core.common.FlashRecyclingFilter.doFilterInternal(FlashRecyclingFilter.java:22) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.dc.core.common.StripJSessionIdFilter.doFilter(StripJSessionIdFilter.java:101) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) […]

使用Spring显示JSP上的值列表

我想在我的jsp视图中显示我的值列表,但我无法做到这一点。 这是我的控制器类,它只是将List添加到ModelAndView映射,而不是重定向到我的index.jsp页面。 EmployeeController @Controller public class EmployeeController { @RequestMapping(value={“/employee”}, method = RequestMethod.GET) public String listEmployee(){ System.out.println(“Kontroler EmployeeController”); LinkedList list = getList(); ModelAndView map = new ModelAndView(“index”); map.addObject(“lists”, list); return map.getViewName(); } private LinkedList getList(){ LinkedList list = new LinkedList(); list.add(“Item 1”); list.add(“Item 2”); list.add(“Item 3”); return list; } } 的index.jsp Welcome to Spring Web MVC […]

如何锁定文件

我有一个write方法,应该安全地将数据写入文件。 // The current file I am writing to. FileOutputStream file = null; … // Synchronized version. private void write(byte[] bytes) { if (file != null && file.getChannel() != null) { try { boolean written = false; do { try { // Lock it! FileLock lock = file.getChannel().lock(); try { // Write the bytes. file.write(bytes); […]