gpt4 book ai didi

java - 如何使用spring security访问根服务器中的文件

转载 作者:行者123 更新时间:2023-11-28 23:21:55 25 4
gpt4 key购买 nike

我正在使用 grails 3.1.1我已经使用 tomcat 8 部署了我的 war 文件,并将所有图像文件存储到 /app/Item/

这是我服务器中文件夹的结构。

/app/Item/<all my image>
/home
/root/apache-tomcat-8/
/apache-tomcat-8/webapps
/apache-tomcat-8/webapps/ROOT.war
/apache-tomcat-8/bin
/apache-tomcat-8/logs
/apache-tomcat-8/work
/apache-tomcat-8/temp
/apache-tomcat-8/conf

现在我正在使用 symlink访问 /app/Item所以我在 /apache-tomcat-8/webapps/images 中创建了一个符号链接(symbolic link)名字images所以当我访问 localhost:8080/images/100.JPG它将访问 /app/Item/100.JPG

但是如果我重新运行我的 tomcat,我会得到一些错误日志,因为文件夹 images我用 symlink 创建的地方不在我的 grails 项目中。像这样..

28-Feb-2017 12:43:44.962 WARNING [localhost-startStop-2] org.apache.naming.NamingContext.lookup Unexpected exception resolving reference
java.sql.SQLException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java.net.URLClassLoader@1fb3ebeb;ClassLoader:ParallelWebappClassLoader
context: gambarku
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1fb3ebeb

at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:283)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:718)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:650)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)

现在我想知道如何访问我的文件夹/app/Item/没有symlink但是来 self 的 grails 应用程序?

我尝试在没有 symlink 的情况下进行部署或 images的文件夹(快捷方式)

    [root@li1447-147 bin]# cd ..
[root@li1447-147 apache-tomcat-8.5.8]# cd we
-bash: cd: we: No such file or directory
[root@li1447-147 apache-tomcat-8.5.8]# cd webapps/
[root@li1447-147 webapps]# rm -rf *
[root@li1447-147 webapps]# clear
[root@li1447-147 webapps]# cd ..
[root@li1447-147 apache-tomcat-8.5.8]# cd bin/
[root@li1447-147 bin]# ./startup.sh
Using CATALINA_BASE: /root/apache-tomcat-8.5.8
Using CATALINA_HOME: /root/apache-tomcat-8.5.8
Using CATALINA_TMPDIR: /root/apache-tomcat-8.5.8/temp
Using JRE_HOME: /usr/java/jdk1.8.0_112
Using CLASSPATH: /root/apache-tomcat-8.5.8/bin/bootstrap.jar:/root/apache- tomcat-8.5.8/bin/tomcat-juli.jar
Tomcat started.
[root@li1447-147 bin]# tail -f ../logs/catalina.out
28-Feb-2017 16:13:06.353 INFO [main] org.apache.coyote.AbstractProtocol.init Ini tializing ProtocolHandler ["http-nio-80"]
28-Feb-2017 16:13:06.368 INFO [main] org.apache.tomcat.util.net.NioSelectorPool. getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.370 INFO [main] org.apache.coyote.AbstractProtocol.init Ini tializing ProtocolHandler ["https-jsse-nio-443"]
28-Feb-2017 16:13:06.613 INFO [main] org.apache.tomcat.util.net.NioSelectorPool. getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.613 INFO [main] org.apache.coyote.AbstractProtocol.init Ini tializing ProtocolHandler ["ajp-nio-8009"]
28-Feb-2017 16:13:06.615 INFO [main] org.apache.tomcat.util.net.NioSelectorPool. getSharedSelector Using a shared selector for servlet write/read
28-Feb-2017 16:13:06.615 INFO [main] org.apache.catalina.startup.Catalina.load I nitialization processed in 796 ms
28-Feb-2017 16:13:06.637 INFO [main] org.apache.catalina.core.StandardService.st artInternal Starting service Catalina
28-Feb-2017 16:13:06.637 INFO [main] org.apache.catalina.core.StandardEngine.sta rtInternal Starting Servlet Engine: Apache Tomcat/8.5.8
28-Feb-2017 16:13:06.657 INFO [localhost-startStop-1] org.apache.catalina.startu p.HostConfig.deployWAR Deploying web application archive /root/apache-tomcat-8.5 .8/webapps/ROOT.war
28-Feb-2017 16:13:13.193 INFO [localhost-startStop-1] org.apache.jasper.servlet. TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scan ned but no TLDs were found in them. Skipping unneeded JARs during scanning can i mprove startup time and JSP compilation time.

Configuring Spring Security Core ...
... finished configuring Spring Security Core

28-Feb-2017 16:13:49.628 INFO [localhost-startStop-1] org.apache.catalina.startu p.HostConfig.deployWAR Deployment of web application archive /root/apache-tomcat -8.5.8/webapps/ROOT.war has finished in 42,968 ms
28-Feb-2017 16:13:49.632 INFO [main] org.apache.coyote.AbstractProtocol.start St arting ProtocolHandler [http-nio-80]
28-Feb-2017 16:13:49.638 INFO [main] org.apache.coyote.AbstractProtocol.start St arting ProtocolHandler [https-jsse-nio-443]
28-Feb-2017 16:13:49.639 INFO [main] org.apache.coyote.AbstractProtocol.start St arting ProtocolHandler [ajp-nio-8009]
28-Feb-2017 16:13:49.640 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 43024 ms

-----------------这是给symlink

然后我尝试read this并将此代码添加到我的 server.xml

<Context docBase="/app/Item" path="/gambarku" />

然后再次启动.sh。

我得到了这个日志。

28-Feb-2017 17:00:49.701 WARNING [localhost-startStop-1] org.apache.catalina.core.NamingContextListener.addResource Failed to register in JMX: javax.naming.NamingException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:java.net.URLClassLoader@1fb3ebeb;ClassLoader:ParallelWebappClassLoader
context: gambarku
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1fb3ebeb

28-Feb-2017 17:00:49.772 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /root/apache-tomcat-8.5.8/webapps/ROOT.war
28-Feb-2017 17:00:56.238 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

当我尝试使用 symlink 时,这个日志是相同的.

我试图找到一些文档并且我已经 checkin 了文件夹 WEB-INF/lib/mysql-connector-java-5.1.20.jar和 build.gradle 与 runtime 'mysql:mysql-connector-java:5.1.20'

enter image description here

enter image description here

最佳答案

def image = new File('/app/Item/image1.jpg')

关于java - 如何使用spring security访问根服务器中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42509285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com